1.卸载MariaDB
[root@localhost ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.65-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs
[root@localhost ~]#
[root@localhost ~]# rpm -qa | grep mariadb
[root@localhost ~]#
2.下载mysql安装包
去官网下载mysql5.7.22,如果需要资源请留言
3.解压安装包
[root@localhost mysql]# pwd
/opt/wangqiqi/mysql
[root@localhost mysql]# ll
总用量 584012
-rw-r--r--. 1 root root 598026240 5月 22 14:11 mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
[root@localhost mysql]# tar -xvf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
mysql-community-libs-5.7.22-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm
mysql-community-embedded-5.7.22-1.el7.x86_64.rpm
mysql-community-test-5.7.22-1.el7.x86_64.rpm
mysql-community-server-5.7.22-1.el7.x86_64.rpm
mysql-community-client-5.7.22-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.22-1.el7.x86_64.rpm
mysql-community-devel-5.7.22-1.el7.x86_64.rpm
mysql-community-common-5.7.22-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.22-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.22-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.22-1.el7.x86_64.rpm
[root@localhost mysql]#
4.按照如下4个命令执行
[root@localhost mysql]# rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.22-1.e################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.22-1.el7################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.22-1.e################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm --nodeps --force
警告:mysql-community-server-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.22-1.e################################# [100%]
[root@localhost mysql]#
[root@localhost mysql]#
[root@localhost mysql]# rpm -qa|grep mysql
mysql-community-libs-5.7.22-1.el7.x86_64
mysql-community-server-5.7.22-1.el7.x86_64
mysql-community-common-5.7.22-1.el7.x86_64
mysql-community-client-5.7.22-1.el7.x86_64
[root@localhost mysql]#
5.初始化mysql
[root@localhost mysql]# mysqld --initialize
[root@localhost mysql]# chown mysql:mysql -R /var/lib/mysql
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl enable mysqld
[root@localhost mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2020-05-22 14:20:15 CST; 15s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 1436 (mysqld)
CGroup: /system.slice/mysqld.service
└─1436 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
5月 22 14:20:15 localhost.localdomain systemd[1]: Starting MySQL Server...
5月 22 14:20:15 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost mysql]#
6.重置密码
[root@localhost mysql]#
[root@localhost mysql]# cat /var/log/mysqld.log |grep password
2020-05-22T06:17:10.274698Z 1 [Note] A temporary password is generated for root@localhost: V>r0T*K>W(M:
[root@localhost mysql]#
[root@localhost mysql]#
[root@localhost mysql]#
[root@localhost mysql]#
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password By 'mysql';
Query OK, 0 rows affected (0.01 sec)
mysql>
7.远程访问授权
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> grant all PRIVILEGES on *.* to 'root'@'%' identified by 'mysql' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>