mysql快速部署
详细步骤
(1)卸载残留
# 查看有关mysql包
[root@192 mysql]# rpm -qa | grep mysql
mysql80-community-release-el8-1.noarch
# 卸载mysql相关包
[root@192 mysql]# rpm -e --nodeps mysql80-community-release-el8-1.noarch
# 查看是否卸载
[root@192 mysql]# rpm -qa | grep mysql
(2)下载yum源
##wegt下载mysql
[root@192 mysql]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
--2022-10-21 09:39:45-- http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 23.203.29.47
正在连接 repo.mysql.com (repo.mysql.com)|23.203.29.47|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9116 (8.9K) [application/x-redhat-package-manager]
正在保存至: “mysql57-community-release-el7-8.noarch.rpm”
100%[==============================================>] 9,116 --.-K/s 用时 0s
2022-10-21 09:39:46 (255 MB/s) - 已保存 “mysql57-community-release-el7-8.noarch.rpm” [9116/9116])
(3)安装yum源
[root@192 mysql]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
[root@192 mysql]# yum install mysql-server
[root@192 mysql]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
(4)查看密码
# 先删除掉mysql文件中的/var/lib/mysql
[root@192 mysql]# rm -rf /var/lib/mysql
# 然后重启mysql服务
[root@192 mysql]# systemctl restart mysqld
# 查看密码
[root@192 mysql]# grep 'temporary password' /var/log/mysqld.log
2022-10-21T01:45:32.169299Z 1 [Note] A temporary password is generated for root@localhost: gPnuC1fdmi;4
(5)登录mysql
# 登录mysql
[root@192 mysql]# mysql -uroot -p临时密码
(6)更改MySQL密码
# 输入命令,设置密码强度:
[root@192 mysql]# set global validate_password_policy=LOW;
# 输入命令,设置密码长度为6,默认为8(若你设的密码超过8位则不需要修改)
[root@192 mysql]# set global validate_password_length=6;
# 设置新密码
[root@192 mysql]# set password=password('123456');
##如若报下方错误,则是你的密码太简单:
(7)登录并查看
[root@192 mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.40
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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> set global validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)
mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
Bye
[root@192 mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.40 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)