安装Mysql

检查是否已安装其他数据库版本

1
rpm -qa | grep mariadb

卸载已安装数据库

1
yum remove mariadb-libs

安装Mysql8.x版本 yum库

1
rpm -ivh http://repo.mysql.com/mysql80-community-release-el7-9.noarch.rpm 

Mysql更新密钥,如若密钥过期,则改为最新的

1
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

如果因为一些原因一直无法导入,可直接创建一个文件,本地进行导入(网址看更新密钥的网址)

1
2
3
4
5
6
//创建密钥文件
touch RPM-GPG-KEY-mysql-2023 (RPM-GPG-KEY-mysql-2023是文件名,下述一样)
//通过vi编辑器进入密钥文件
vi RPM-GPG-KEY-mysql-2023
//本地进行导入密钥文件
rpm --import RPM-GPG-KEY-mysql-2023

下面提供2023年的Mysql密钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQINBGU2rNoBEACSi5t0nL6/Hj3d0PwsbdnbY+SqLUIZ3uWZQm6tsNhvTnahvPPZ
BGdl99iWYTt2KmXp0KeN2s9pmLKkGAbacQP1RqzMFnoHawSMf0qTUVjAvhnI4+qz
MDjTNSBq9fa3nHmOYxownnrRkpiQUM/yD7/JmVENgwWb6akZeGYrXch9jd4XV3t8
OD6TGzTedTki0TDNr6YZYhC7jUm9fK9Zs299pzOXSxRRNGd+3H9gbXizrBu4L/3l
UrNf//rM7OvV9Ho7u9YYyAQ3L3+OABK9FKHNhrpi8Q0cbhvWkD4oCKJ+YZ54XrOG
0YTg/YUAs5/3//FATI1sWdtLjJ5pSb0onV3LIbarRTN8lC4Le/5kd3lcot9J8b3E
MXL5p9OGW7wBfmNVRSUI74Vmwt+v9gyp0Hd0keRCUn8lo/1V0YD9i92KsE+/IqoY
Tjnya/5kX41jB8vr1ebkHFuJ404+G6ETd0owwxq64jLIcsp/GBZHGU0RKKAo9DRL
H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O6WaQawcVMlQO1SX0giB+3/DryfN9VuIYd1EWCGQa3O0MVu6o5KVHwPgl9
R1P6xPZhurkDpAd0b1s4fFxin+MdxwmG7RslZA9CXRPpzo7/fCMW8sYOH15DP+Yf
UckoEreBt+zezBxbIX2CGGWEV9v3UBXadRtwxYQ6sN9bqW4jm1b41vNA17b6CVH6
sVgtU3eN+5Y9an1e5jLD6kFYx+OIeqIIId/TEqwS61csY9aav4j4KLOZFCGNU0FV
ji7NQewSpepTcJwfJDOzmtiDP4vol1ApJGLRwZZZ9PB6wsOgDOoP6sr0YrDI/NNX
2RyXXbglnQ1yJZVSH3/3eo6knG2qTthUKHCRDNKdy9Qqc1x4WWWtSRjh+zX8AvJK
2q1rVLH2/3ilxe9wcAZUlaj3id3TxquAlud4lWDz
=h5nH
-----END PGP PUBLIC KEY BLOCK-----

使用yum下载安装MySQL8.0

1
yum install -y mysql-community-server

配置MySQL

修改root的权限和密码

1
2
3
4
//进入vi编辑器
vi /etc/my.cnf
//在[mysqld]下面加入配置
skip-grant-tables

用root进入MySQL

1
mysql -u root

将root密码置空

1
update user SET authentication_string='' WHERE user = 'root';

退出MySQL登录,将跳过权限验证选项skip-grant-tables去掉

1
vim /etc/my.cnf

重启mysqld

1
systemctl restart mysqld

重新登录mysql

1
mysql -u root

将MySQL密码改为123456

1
2
3
4
5
6
7
8
9
10
//修改root密码
alter user 'root'@'localhost' identified by 'Zxc@12345678';
//修改密码长度
set global validate_password.length=6;
//修改密码等级
set global validate_password.policy=LOW;
//再次修改root密码
alter user 'root'@'localhost' identified by '123456';
//刷新权限
flush privileges;

手动修改root用户的访问范围

1
2
3
use mysql;
select host,user from user;
update user set host = '%' where host = 'localhost' and user = 'root';

本文未经允许禁止转载,可提供参考,如需源码请移至关于页。

本文作者:Acknowledging
原文地址:https://qjwbkk.top