Rocky Linux 9.2 安装MySQL5.7

tee /etc/yum.repos.d/mysql-community.repo<<EOF
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/\$basearch/
enabled=1
gpgcheck=0

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/\$basearch/
enabled=1
gpgcheck=0

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/\$basearch/
enabled=1
gpgcheck=0
EOF

dnf config-manager --disable mysql80-community
dnf config-manager --enable mysql57-community

dnf install -y libncurses* ncurses-devel
dnf --enablerepo=devel install -y ncurses-compat-libs
dnf install -y mysql-community-server
grep 'A temporary password' /var/log/mysqld.log |tail -1
# 2023-06-28T08:33:42.179329Z 1 [Note] A temporary password is generated for root@localhost: gkNH%eAMe6a?

# 修改密码,方式1
mysqladmin -uroot -pgkNH%eAMe6a? password 新密码

# 连接之后第一件事是修改密码,方式2
mysql -uroot -pgkNH%eAMe6a?
alter user 'root'@'localhost' identified by '新密码';

# 设置弱口令,修改完后只验证密码长度
set global validate_password_policy=0;
# 修改密码长度策略
set global validate_password_length=1;

# 更改用户的访问权限(%代表任何地址都可以访问)
use mysql;
update user set host = '%' where user = 'root';
flush privileges;