在Rocky Linux 9.x上安装MySQL 8.x
先更新Rocky的源到境内:
# sed -e ‘s|^mirrorlist=|#mirrorlist=|g’ \
-e ‘s|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.sjtug.sjtu.edu.cn/rocky|g‘ \
-i.bak \
/etc/yum.repos.d/rocky*.repo
# dnf makecache –releasever 9
安装:
# wget https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm
# dnf install -y ./mysql84-community-release-el9-1.noarch.rpm
# dnf install -y mysql-community-server –releasever 9
修改配置文件:
# vi /etc/my.cnf
…
[mysqld]
…
user=mysql
mysql_native_password=ON
启动:
# systemctl start mysqld.service
# systemctl enable mysqld.service
# systemctl status mysqld.service
登录:
# grep “password” /var/log/mysqld.log
2024-08-16T10:19:26.880855Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: R7)W&&/JsX(G
# mysql -uroot -p
输入上面的密码登录进去,查看插件,保证mysql_native_password激活以便和5.x版本的密码算法兼容:
> show plugins;
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
把密码验证改成最简单的(线上系统不建议):
> ALTER USER ‘root’@’localhost’ IDENTIFIED BY “1234@abcd”;
> set global validate_password.policy=0;
> set global validate_password.length=1;
> ALTER USER ‘root’@’localhost’ IDENTIFIED BY “123456”;
> use mysql;
> select * from user;
> CREATE USER ‘root’@’%’ IDENTIFIED BY ‘123456’;
(如果从老版本升级:> CREATE USER ‘root’@’%’ IDENTIFIED WITH ‘mysql_native_password’ BY ‘123456’ )
> GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ WITH GRANT OPTION;
> FLUSH PRIVILEGES;
移除:
# dnf remove mysql-server
# dnf remove mysql-server-common-*
# dnf list installed | grep mysql