centos 7 使用RPM安装mysql 8
centos7 自己带着 mariadb, mariadb是mysql的一个分支, 如果要安装mysql数据库, 需要清理掉
# 搜索是否已经安装
rpm -qa | grep mysql
rpm -qa | grep mariadb
# 清理命令
rpm -e mariadb-libs******_64
如果rpm -e删除失败, 提示有依赖关系的软件需要安装, 可以使用 yum remove + 包名 来删除 mariadb
开始安装
一般使用yum直接安装是可以的, 但是有个问题, yum是到默认的mariadb用的yum源去找, 可能会找不到,所以我们自己来安装
需要的rpm包列表
mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm
mysql-community-common-8.0.22-1.el7.x86_64.rpm
mysql-community-libs-8.0.22-1.el7.x86_64.rpm
mysql-community-client-8.0.22-1.el7.x86_64.rpm
mysql-community-server-8.0.22-1.el7.x86_64.rpm
# rpm -ivh + 包安装所有的包
rpm -ivh mysql-community-server-8.0.22-1.el7.x86_64.rpm
报错:
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-8.0.22-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.22-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.22-1.el7.x86_64
解决方式:yum install libaio
# 初始化数据库
mysqld --initialize
# 启动mysql
service mysqld start
启动失败时, 可以查看日志 cat /var/log/mysqld.log
错误信息:
2021-01-08T12:25:36.325615Z 1 [ERROR] [MY-012271] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2021-01-08T12:25:36.325816Z 1 [ERROR] [MY-012278] [InnoDB] The innodb_system data file 'ibdata1' must be writable
解决办法:
chown -R mysql:mysql /var/lib/mysql
#chmod -R 777 /var/lib/mysql
启动:
systemctl start mysqld.service
初始化密码
首先关闭mysqld服务
systemctl stop mysqld.service在/etc/my.cnf后 加上
skip-grant-tables无密码登陆
mysql -u root -p充值密码
> use mysql;
> update user set authentication_string='' where user='root'; -- 重置密码为空
> quit; -- 退出
- 重新登陆,更改登陆密码
首先要去掉 my.cnf里的skip-grant-tables, 然后重启服务
mysql -u root -p -- 直接登陆
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; -- 更改密码
flush privileges
- 正常登陆