一、卸载MySQL
- 卸载系统自带的mariadb
rpm -qa|grep mariadb
rpm -e mariadb-libs --nodeps
rpm -qa|grep mariadb
- 卸载MySQL
systemctl stop mysqld.service
rpm -qa | grep -i mysql
yum remove mysql-community-libs-5.7.29-1.el7.x86_64 mysql-community-common-5.7.29-1.el7.x86_64 mysql-community-client-5.7.29-1.el7.x86_64 mysql-community-server-5.7.29-1.el7.x86_64
rpm -qa | grep -i mysql
find / -name mysql
rm -rf /etc/my.cnf
rm -rf /var/log/mysqld.log
二、安装MySQL
- 创建MySQL目录
mkdir /export/server/mysql
- 上传压缩包到该文件夹
- 解压压缩包
tar -xvf mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar
- 执行安装
yum -y install libaio
rpm -ivh mysql-community-client-5.7.34-1.el7.x86_64.rpm mysql-community-common-5.7.34-1.el7.x86_64.rpm mysql-community-devel-5.7.34-1.el7.x86_64.rpm mysql-community-embedded-5.7.34-1.el7.x86_64.rpm mysql-community-embedded-compat-5.7.34-1.el7.x86_64.rpm mysql-community-embedded-devel-5.7.34-1.el7.x86_64.rpm mysql-community-libs-5.7.34-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.34-1.el7.x86_64.rpm mysql-community-server-5.7.34-1.el7.x86_64.rpm
三、配置MySQL
-
初始化 mysqld --initialize
-
更改所属组 chown mysql:mysql /var/lib/mysql -R
-
启动MySQL systemctl start mysqld.service
-
查看生成的临时root密码 cat /var/log/mysqld.log
-
登录MySQL mysql -uroot -p
临时root密码
-
修改root密码
alter user user() identified by "123456";
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
-
查看、开启、关闭mysql服务
systemctl status mysqld
systemctl stop mysqld
systemctl status mysqld
systemctl start mysqld
systemctl status mysqld
-
设置开机自动启动 systemctl enable mysqld
-
查看是否设置成功 systemctl list-unit-files | grep mysqld
|