centos7安装mysql5.6.38史上最详细的安装步骤

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 最近由于要用到mysql,就想着装一个mysql,但是因为我的虚拟机是centos7的,centos7将默认数据库mysql替换成了Mariadb安装起来就比较的麻烦,遇到各种各样的问题,网上的教程很多,但是基本没有好使的,按照他们的步骤到最后没有一个成功的,搞了很长时间才装好,我记得之前在centos6.5上面安装也没那么复杂啊,但是在7上面不管是用yum方式,还是安装包的方式都搞了好几遍,最后用安装包的方式安装成功了,今天就来总结一下安装的过程.为了方便大家看整个过程,我又重新装了一遍.过程写的比较详细,建议大家先收藏在观看.

最近由于要用到mysql,就想着装一个mysql,但是因为我的虚拟机是centos7的,centos7将默认数据库mysql替换成了Mariadb安装起来就比较的麻烦,遇到各种各样的问题,网上的教程很多,但是基本没有好使的,按照他们的步骤到最后没有一个成功的,搞了很长时间才装好,我记得之前在centos6.5上面安装也没那么复杂啊,但是在7上面不管是用yum方式,还是安装包的方式都搞了好几遍,最后用安装包的方式安装成功了,今天就来总结一下安装的过程.为了方便大家看整个过程,我又重新装了一遍.过程写的比较详细,建议大家先收藏在观看.


1.下载安装包,我用的是5.6.38这个版本,最好是去官网下载.


2.检查是否安装过mysql,如果有先卸载, rpm -qa|grep -i mysql


用yum -y remove删除,如果有多个,一个一个执行,卸载不掉的用 rpm -ev


然后执行find / -name mysql|xargs rm -rf 删除所有mysql的文件夹


3.卸载系统自带的Mariadb


[root@storm2 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@storm2 ~]#


卸载:rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64,再次执行查看发现已经不存在mariadb了.


4.删除etc目录下的my.cnf


[root@storm2 ~]# rm /etc/my.cnf


5.创建mysql用户组并且创建一个用户名为mysql的用户并加入mysql用户组


[root@storm2 ~]# groupadd mysql
[root@storm2 ~]# useradd -g mysql mysql


6.把下载的压缩包上传到 /usr/local/ 目录下


[root@storm2 ~]# cd /usr/local/
[root@storm2 local]# ll
total 321036
drwxr-xr-x. 2 root root         6 Nov  5  2016 bin
drwxr-xr-x. 2 root root         6 Nov  5  2016 etc
drwxr-xr-x. 2 root root         6 Nov  5  2016 games
drwxr-xr-x. 2 root root         6 Nov  5  2016 include
drwxr-xr-x. 2 root root         6 Nov  5  2016 lib
drwxr-xr-x. 2 root root         6 Nov  5  2016 lib64
drwxr-xr-x. 2 root root         6 Nov  5  2016 libexec
-rw-r--r--. 1 root root 328739574 Jan  3  2018 mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 2 root root         6 Nov  5  2016 sbin
drwxr-xr-x. 5 root root        49 Dec 26  2017 share
drwxr-xr-x. 2 root root         6 Nov  5  2016 src


7.解压tar包,并重命名.


tar -zxvf mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz 
mv mysql-5.6.38-linux-glibc2.12-x86_64 mysql


8.复制一份/usr/local/mysql/support-files/下的my-default.cnf文件到/etc下面.


cp support-files/my-default.cnf /etc/my.cnf


9.配置/etc目录下的my.cnf文件,vi /etc/my.cnf


[mysql]
# 设置mysql客户端默认字符集
character-set-server=utf8  
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306 
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_name=1
max_allowed_packet=16M


10.进入安装mysql目录,给mysql用户赋权限.


[root@master mysql]# cd /usr/local/mysql/
[root@master mysql]# chown -R mysql:mysql ./


11.安装数据库


[root@storm2 mysql]#  ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 
Installing MySQL system tables...2019-01-12 03:33:15 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-01-12 03:33:15 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-01-12 03:33:15 0 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.6.38) starting as process 3620 ...
2019-01-12 03:33:15 3620 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-01-12 03:33:15 3620 [Note] InnoDB: The InnoDB memory heap is disabled
2019-01-12 03:33:15 3620 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-01-12 03:33:15 3620 [Note] InnoDB: Memory barrier is not used
2019-01-12 03:33:15 3620 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-01-12 03:33:15 3620 [Note] InnoDB: Using Linux native AIO
2019-01-12 03:33:15 3620 [Note] InnoDB: Using CPU crc32 instructions
2019-01-12 03:33:15 3620 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-01-12 03:33:16 3620 [Note] InnoDB: Completed initialization of buffer pool
2019-01-12 03:33:16 3620 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2019-01-12 03:33:16 3620 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2019-01-12 03:33:16 3620 [Note] InnoDB: Database physically writes the file full: wait...
2019-01-12 03:33:16 3620 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2019-01-12 03:33:17 3620 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2019-01-12 03:33:17 3620 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2019-01-12 03:33:17 3620 [Warning] InnoDB: New log files created, LSN=45781
2019-01-12 03:33:17 3620 [Note] InnoDB: Doublewrite buffer not found: creating new
2019-01-12 03:33:17 3620 [Note] InnoDB: Doublewrite buffer created
2019-01-12 03:33:17 3620 [Note] InnoDB: 128 rollback segment(s) are active.
2019-01-12 03:33:17 3620 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-01-12 03:33:17 3620 [Note] InnoDB: Foreign key constraint system tables created
2019-01-12 03:33:17 3620 [Note] InnoDB: Creating tablespace and datafile system tables.
2019-01-12 03:33:17 3620 [Note] InnoDB: Tablespace and datafile system tables created.
2019-01-12 03:33:17 3620 [Note] InnoDB: Waiting for purge to start
2019-01-12 03:33:17 3620 [Note] InnoDB: 5.6.38 started; log sequence number 0
2019-01-12 03:33:18 3620 [Note] Binlog end
2019-01-12 03:33:18 3620 [Note] InnoDB: FTS optimize thread exiting.
2019-01-12 03:33:18 3620 [Note] InnoDB: Starting shutdown...
2019-01-12 03:33:19 3620 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2019-01-12 03:33:19 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-01-12 03:33:19 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-01-12 03:33:19 0 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.6.38) starting as process 3645 ...
2019-01-12 03:33:19 3645 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-01-12 03:33:19 3645 [Note] InnoDB: The InnoDB memory heap is disabled
2019-01-12 03:33:19 3645 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-01-12 03:33:19 3645 [Note] InnoDB: Memory barrier is not used
2019-01-12 03:33:19 3645 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-01-12 03:33:19 3645 [Note] InnoDB: Using Linux native AIO
2019-01-12 03:33:19 3645 [Note] InnoDB: Using CPU crc32 instructions
2019-01-12 03:33:19 3645 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-01-12 03:33:19 3645 [Note] InnoDB: Completed initialization of buffer pool
2019-01-12 03:33:20 3645 [Note] InnoDB: Highest supported file format is Barracuda.
2019-01-12 03:33:20 3645 [Note] InnoDB: 128 rollback segment(s) are active.
2019-01-12 03:33:20 3645 [Note] InnoDB: Waiting for purge to start
2019-01-12 03:33:20 3645 [Note] InnoDB: 5.6.38 started; log sequence number 1625977
2019-01-12 03:33:20 3645 [Note] Binlog end
2019-01-12 03:33:20 3645 [Note] InnoDB: FTS optimize thread exiting.
2019-01-12 03:33:20 3645 [Note] InnoDB: Starting shutdown...
2019-01-12 03:33:21 3645 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
  /usr/local/mysql//bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql//bin/mysqladmin -u root -h storm2 password 'new-password'
Alternatively you can run:
  /usr/local/mysql//bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
  cd . ; /usr/local/mysql//bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
  cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
 http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/local/mysql//my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server


12.修改当前data目录的拥有者为mysql用户


[root@storm2 mysql]# chown -R mysql:mysql data


13.授予my.cnf最大权限


[root@storm2 mysql]# chmod 777 /etc/my.cnf


14.设置开机自启动服务控制脚本:


[root@storm2 mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld


15.增加mysqld服务控制脚本执行权限


[root@storm2 mysql]# chmod +x /etc/rc.d/init.d/mysqld


16.将mysqld服务加入到系统服务,并检查mysqld服务是否生效,出现下图所示,表示已经生效


[root@storm2 mysql]# chkconfig --add mysqld
[root@storm2 mysql]# chkconfig --list mysqld
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
mysqld          0:off 1:off 2:on  3:on  4:on  5:on  6:off


17,最后启动mysql.


[root@storm2 mysql]# service mysqld start
Warning: World-writable config file '/etc/my.cnf' is ignored
Starting MySQL.Warning: World-writable config file '/etc/my.cnf' is ignored
Warning: World-writable config file '/etc/my.cnf' is ignored
Logging to '/usr/local/mysql/data/storm2.err'.
....... SUCCESS!


18,以root账户登录mysql,默认是没有密码的


[root@storm2 bin]# mysql -uroot -p
Warning: World-writable config file '/etc/my.cnf' is ignored
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>


要输入密码的时候直接回车即可。


19.修改密码


mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password('12345678') where user='mysql' and host='localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


20.设置远程主机登录,不然在连接的时候会报错


mysql> GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'%' IDENTIFIED BY '12345678' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)


到这整个mysql的安装过程就结束了.

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
23天前
|
安全 关系型数据库 MySQL
CentOS7仅安装部署MySQL80客户端
通过上述步骤,你可以在CentOS 7上成功安装并配置MySQL 8.0客户端。这个过程确保你能够使用MySQL客户端工具连接和管理远程的MySQL数据库,而不需要在本地安装MySQL服务器。定期更新MySQL客户端可以确保你使用的是最新的功能和安全修复。
105 16
|
2月前
|
关系型数据库 MySQL 数据库
【MySQL基础篇】MySQL概述、Windows下载MySQL8.0超详细图文安装教程
在这一章节,主要介绍两个部分,数据库相关概念及MySQL数据库的介绍、下载、安装、启动及连接。接着,详细描述了MySQL 8.0的版本选择与下载,推荐使用社区版(免费)。安装过程包括自定义安装路径、配置环境变量、启动和停止服务、以及客户端连接测试。此外,还提供了在同一台电脑上安装多个MySQL版本的方法及卸载步骤。最后,解释了关系型数据库(RDBMS)的特点,即基于二维表存储数据,使用SQL语言进行操作,格式统一且便于维护。通过具体的结构图展示了MySQL的数据模型,说明了数据库服务器、数据库、表和记录之间的层次关系。
【MySQL基础篇】MySQL概述、Windows下载MySQL8.0超详细图文安装教程
|
2月前
|
NoSQL 关系型数据库 Redis
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
104 14
|
29天前
|
关系型数据库 MySQL 应用服务中间件
《docker基础篇:8.Docker常规安装简介》包括:docker常规安装总体步骤、安装tomcat、安装mysql、安装redis
《docker基础篇:8.Docker常规安装简介》包括:docker常规安装总体步骤、安装tomcat、安装mysql、安装redis
86 7
|
2月前
|
安全 关系型数据库 MySQL
Windows Server 安装 MySQL 8.0 详细指南
安装 MySQL 需要谨慎,特别注意安全配置和权限管理。根据实际业务需求调整配置,确保数据库的性能和安全。
173 9
|
16天前
|
存储 分布式计算 Hadoop
Centos7.9安装kerberos
Centos7.9安装kerberos
67 25
|
11天前
|
存储 Shell 网络安全
Centos7.9安装openldap
Centos7.9安装openldap
41 16
|
12天前
|
数据可视化 Linux 应用服务中间件
Centos7.9安装phpldapadmin
Centos7.9安装phpldapadmin
42 15
|
15天前
|
网络协议 Java 应用服务中间件
centos7环境下tomcat8的安装与配置
本文介绍了在Linux环境下安装和配置Tomcat 8的详细步骤。首先,通过无网络条件下的文件交互软件(如Xftp 6或MobaXterm)下载并解压Tomcat安装包至指定路径,启动Tomcat服务并测试访问。接着,修改Tomcat端口号以避免冲突,并部署Java Web应用项目至Tomcat服务器。最后,调整Linux防火墙规则,确保外部可以正常访问部署的应用。关键步骤包括关闭或配置防火墙、添加必要的端口规则,确保Tomcat服务稳定运行。
|
3月前
|
SQL 存储 Linux
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第16天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括配置系统源、安装 SQL Server 2019 软件包以及数据库初始化,确保 SQL Server 正常运行。
135 4