Centos7下Mysql5.7详细安装步骤

Centos7下Mysql5.7详细安装步骤

武深龙 2018-5-14

切记,mysql5.7以后默认是有初始化密码的,另外Centos7中关闭防火墙的命令与之前版本不大一样,本人在安装过程中此两处有些波折。

1.首先查找Centos7是否默认安装mariadb,具体命令如下:

# rpm -qa|grep mariadb

2.如果存在mariadb,则执行如下命令进行卸载:

# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

3.再次确认mariadb是否卸载干净,具体命令如下:

# rpm -qa|grep mariadb

4.创建mysql所在的用户组,具体命令如下:

# groupadd mysql

5.创建mysql所使用的用户,具体命令如下:

# useradd -g mysql mysql

6.将mysql安装包拷贝到Centos7内,本文档默认拷贝到/wsl目录下,解压安装包命令如下:

#tar -zxvf /wsl/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

7.在根目录下创建一个子目录work,命令如下:

#mkdir work

8.将解压后的mysql目录移动至/work目录下并且改名为mysql,具体命令如下:

#mv /wsl/mysql-5.7.22-linux-glibc2.12-x86_64 /work/mysql

9.修改mysql安装目录的权限,具体命令如下:

#cd /work/mysql

# chown -R mysql . //此命令把当前目录下的文件及目录的属性修改为mysql用户

# chgrp -R mysql . //此命令把当前目录下的文件及目录所属组修改为mysql组

10.创建data目录用于存放数据库文件,具体命令如下:

# mkdir data

11.开始进行mysql系统初始化,执行命令大致如下: # /work/mysql/bin/mysqld --initialize --user=mysql --datadir=/work/mysql/data

--basedir=/work/mysql

执行上述命令的时候一定要注意,系统执行过程中回显内容大致如下:

2018-05-14T01:12:57.186210Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-05-14T01:12:58.102507Z 0 [Warning] InnoDB: New log files created, LSN=45790

2018-05-14T01:12:58.295969Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2018-05-14T01:12:58.370692Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f06157ca-5713-11e8-815a-080027324a9b.

2018-05-14T01:12:58.374250Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2018-05-14T01:12:58.377082Z 1 [Note] A temporary password is generated for root@localhost:

其中最后的一串字符

12.第一次启动mysql,具体命令如下:

# /work/mysql/bin/mysqld_safe --user=mysql &

13.重新打开一个终端窗口或远程访问窗口,查看mysql是否成功启动,如果进程中有就证明启动成功,具体命令如下:

# ps aux |grep mysqld

执行后返回结果大致如下:

root 15164 0.0 0.0 113256 1612 pts/0 S 09:17 0:00 /bin/sh /work/mysql/bin/mysqld_safe --user=mysql

mysql 15234 0.2 4.5 1119180 178276 pts/0 Sl 09:17 0:00

/work/mysql/bin/mysqld --basedir=/work/mysql --datadir=/work/mysql/data --plugin-dir=/work/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=localhost.localdomain.pid

root 15328 0.0 0.0 112664 972 pts/1 R+ 09:19 0:00 grep --color=auto mysqld

14.修改mysql的默认密码,具体命令如下:

# /work/mysql/bin/mysqladmin -uroot -p password Enter password: New password:

Confirm new password:

Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

如果出现大致如上提示,证明密码修改成功。

15.关闭mysql服务,具体命令如下:

# /work/mysql/bin/mysqladmin -uroot -p shutdown Enter password:

关闭服务要求输入密码,此处输入的是修改过的密码。

16.验证mysql是否成功关闭,执行如下命令:

# ps aux |grep mysql

root 15462 0.0 0.0 112664 972 pts/1 R+ 09:25 0:00 grep --color=auto mysql

出现大致如上提示为mysql服务关闭成功。

17.设置mysql为开机启动服务,首先将mysql.server文件拷贝到指定地点,具体命令如下:

# cp /work/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

18.增加mysqld脚本的执行权限,具体命令如下:

# chmod +x /etc/rc.d/init.d/mysqld

19.将mysqld服务加入系统服务,具体命令如下:

# chkconfig --add mysqld

20.检查mysql服务是否生效,具体命令如下:

# chkconfig --list mysqld

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4