[moxi@hadoop102 ~]$ rpm -qa|grep mariadb
如果有,则删除:
[moxi @hadoop102 ~]$ sudo rpm -e --nodeps mariadb-libs
安装包获取链接:链接:https://pan.baidu.com/s/1hyhsFzD2EHGOsI7gGM9AKA?pwd=vrsg
提取码:vrsg
[moxi @hadoop102 software]# tar -xf mysql-5.7.28-1.el7.x86_64.rpmbundle.tar
[moxi @hadoop102 software]$
sudo rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm --force --nodeps
sudo rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm --force --nodeps
sudo rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm --force --nodeps
sudo rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm --force --nodeps
sudo rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm --force --nodeps
注意:按照顺序依次执行
如果 Linux 是最小化安装的,在安装 mysql-community-server-5.7.28-1.el7.x86_64.rpm 时 可能会出现如下错误
[moxi@hadoop102 software]$ sudo rpm -ivh mysql-community-server5.7.28-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.28-1.el7.x86_64.rpm: 头 V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败: libaio.so.1()(64bit) 被 mysql-community-server-5.7.28-1.el7.x86_64
需要 libaio.so.1(LIBAIO_0.1)(64bit) 被 mysql-community-server-5.7.28- 1.el7.x86_64 需要 libaio.so.1(LIBAIO_0.4)(64bit) 被 mysql-community-server-5.7.28- 1.el7.x86_64 需要
通过 yum 安装缺少的依赖,然后重新安装 mysql-community-server-5.7.28-1.el7.x86_64 即 可
[moxi@hadoop102 software] yum install -y libaio
查看 datadir 的值:
[mysqld] datadir=/var/lib/mysql
删除/var/lib/mysql 目录下的所有内容:
[moxi @hadoop102 mysql]# cd /var/lib/mysql
[moxi @hadoop102 mysql]# sudo rm -rf ./*
注意执行命令的位置
[moxi @hadoop102 opt]$ sudo mysqld --initialize --user=mysql
[moxi @hadoop102 opt]$ sudo cat /var/log/mysqld.log
[moxi @hadoop102 opt]$ sudo systemctl start mysqld
[moxi @hadoop102 opt]$ mysql -uroot -p
Enter password: 输入临时生成的密码
mysql> set password = password("123456");
mysql> update mysql.user set host='%' where user='root';
mysql> flush privileges;