Centos7 安装mysql5.6 怕坑记录

1.下载源:

# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2.安装包

# sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

添加mysql 用户权限

3 安装mysql

>>sudo yum install mysql-server --nogpgcheck


已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.5.6.48-2.el6 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 5.6.48-2.el6,它被软件包 mysql-community-server-5.6.48-2.el6.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.6.10,它被软件包 mysql-community-server-5.6.48-2.el6.x86_64 需要
--> 正在处理依赖关系 perl(DBI),它被软件包 mysql-community-server-5.6.48-2.el6.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.5.6.48-2.el6 将被 安装
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 5.6.10,它被软件包 mysql-community-client-5.6.48-2.el6.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.5.6.48-2.el6 将被 安装
---> 软件包 perl-DBI.x86_64.0.1.627-4.el7 将被 安装
--> 正在处理依赖关系 perl(RPC::PlServer) >= 0.2001,它被软件包 perl-DBI-1.627-4.el7.x86_64 需要
--> 正在处理依赖关系 perl(RPC::PlClient) >= 0.2000,它被软件包 perl-DBI-1.627-4.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-libs.x86_64.0.5.6.48-2.el6 将被 安装
---> 软件包 perl-PlRPC.noarch.0.0.2020-14.el7 将被 安装
--> 正在处理依赖关系 perl(Net::Daemon) >= 0.13,它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Net::Daemon::Test),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Net::Daemon::Log),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Compress::Zlib),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在检查事务
---> 软件包 perl-IO-Compress.noarch.0.2.061-2.el7 将被 安装
--> 正在处理依赖关系 perl(Compress::Raw::Zlib) >= 2.061,它被软件包 perl-IO-Compress-2.061-2.el7.noarch 需要
--> 正在处理依赖关系 perl(Compress::Raw::Bzip2) >= 2.061,它被软件包 perl-IO-Compress-2.061-2.el7.noarch 需要
---> 软件包 perl-Net-Daemon.noarch.0.0.48-5.el7 将被 安装
--> 正在检查事务
---> 软件包 perl-Compress-Raw-Bzip2.x86_64.0.2.061-3.el7 将被 安装
---> 软件包 perl-Compress-Raw-Zlib.x86_64.1.2.061-4.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

==================================================================================================================================================================================================================
Package 架构 版本 源 大小
==================================================================================================================================================================================================================
正在安装:
mysql-community-server x86_64 5.6.48-2.el6 mysql56-community 62 M
为依赖而安装:
mysql-community-client x86_64 5.6.48-2.el6 mysql56-community 20 M
mysql-community-common x86_64 5.6.48-2.el6 mysql56-community 341 k
mysql-community-libs x86_64 5.6.48-2.el6 mysql56-community 2.2 M
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k

事务概要
==================================================================================================================================================================================================================
安装 1 软件包 (+9 依赖软件包)

总计:86 M
安装大小:354 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
正在安装 : mysql-community-common-5.6.48-2.el6.x86_64 1/10
正在安装 : mysql-community-libs-5.6.48-2.el6.x86_64 2/10
正在安装 : mysql-community-client-5.6.48-2.el6.x86_64 3/10
正在安装 : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 4/10
正在安装 : perl-Net-Daemon-0.48-5.el7.noarch 5/10
正在安装 : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 6/10
正在安装 : perl-IO-Compress-2.061-2.el7.noarch 7/10
正在安装 : perl-PlRPC-0.2020-14.el7.noarch 8/10
正在安装 : perl-DBI-1.627-4.el7.x86_64 9/10
正在安装 : mysql-community-server-5.6.48-2.el6.x86_64 10/10
验证中 : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 1/10
验证中 : perl-Net-Daemon-0.48-5.el7.noarch 2/10
验证中 : perl-PlRPC-0.2020-14.el7.noarch 3/10
验证中 : mysql-community-client-5.6.48-2.el6.x86_64 4/10
验证中 : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 5/10
验证中 : mysql-community-common-5.6.48-2.el6.x86_64 6/10
验证中 : mysql-community-libs-5.6.48-2.el6.x86_64 7/10
验证中 : mysql-community-server-5.6.48-2.el6.x86_64 8/10
验证中 : perl-DBI-1.627-4.el7.x86_64 9/10
验证中 : perl-IO-Compress-2.061-2.el7.noarch 10/10

已安装:
mysql-community-server.x86_64 0:5.6.48-2.el6

作为依赖被安装:
mysql-community-client.x86_64 0:5.6.48-2.el6 mysql-community-common.x86_64 0:5.6.48-2.el6 mysql-community-libs.x86_64 0:5.6.48-2.el6 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7
perl-PlRPC.noarch 0:0.2020-14.el7

完毕!

4 查看安装位置

whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

5.设置目录用户组权限

[ mysql]# chown -R mysql:mysql /usr/share/mysql/
[ mysql]# chown -R mysql:mysql /var/lib/mysql

6.设置mysql目录 运行初始化权限表

[ mysql]# find / -name ‘mysql_install_db‘
/usr/bin/mysql_install_db

会报错

/usr/bin/mysql_install_db --user=mysql --basedir=/usr/share/mysql --datadir=/var/lib/mysql
FATAL ERROR: Could not find /fill_help_tables.sql

If you compiled from source, you need to run ‘make install‘ to
copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

似乎是编译安装方式 使用cmake 等安装方式才需要

7 提示  RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.

参考生成密钥 解决 https://blog.csdn.net/zhengwei125/article/details/53097365

需要移动到指定目录 /var/lib/mysql//private_key.pem.

8 启动log报错   

 Fatal error: Can‘t open and lock privilege tables: Table ‘mysql.user‘ doesn‘t exist

查证后是 /var/lib/mysql/mysql 里面的数据库初始化没完成

使用命令

 /usr/bin/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/share/mysql/ --datadir=/var/lib/mysql --user=mysql

报错

 [ERROR] Fatal error: Can‘t open and lock privilege tables: Table ‘mysql.user‘ doesn‘t exist

正确的命令格式是 /share/mysql/ 的目录查找在安装命令中已经代入了

/usr/bin/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql

9 成功启动

systemctl start mysqld.service

[ mysql]# systemctl status mysqld.service
● mysqld.service - SYSV: MySQL database server.
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: active (running) since 六 2020-07-04 19:34:20 CST; 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 19959 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
Main PID: 20290 (mysqld)
CGroup: /system.slice/mysqld.service
├─19987 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
└─20290 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/v...

7月 04 19:34:19 games000001 systemd[1]: Starting SYSV: MySQL database server....
7月 04 19:34:20 games000001 mysqld[19959]: Starting mysqld: [ OK ]
7月 04 19:34:20 games000001 systemd[1]: mysqld.service: Supervising process 20290 which is not our child. We‘ll most likely not notice when it exits.
7月 04 19:34:20 games000001 systemd[1]: Started SYSV: MySQL database server..

10. 登入数据库 设置密码 设置远程用户 权限

mysql -uroot

---------------------

mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;

mysql> GRANT ALL PRIVILEGES ON *.* TO ‘LoginName‘@‘%‘ IDENTIFIED BY ‘LoginPwd‘ WITH GRANT OPTION;

mysql> flush privileges;

相关推荐