yum安装MySQL

yum仓库

# MySQL8
yum localinstall https://repo.mysql.com/mysql80-community-release-sles12-6.noarch.rpm

# MySQL5.7
yum localinstall -y https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm

或者

wget -i -c https://repo.mysql.com/mysql80-community-release-sles12-6.noarch.rpm
yum -y install mysql80-community-release-sles12-6.noarch.rpm

yum安装MySQL

yum -y install mysql-community-server

安装过程可能报错,附上解决方案:

错误1
All matches were filtered out by modular filtering for argument: mysql-community-server
Error: Unable to find a match: mysql-community-server

需执行yum module disable mysql
然后重新install

错误2


 失败的软件包是:mysql-community-client-5.7.39-1.el7.x86_64
 GPG  密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

原因: MySQL GPG 密钥已过期导致
解决办法:

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
# 执行完后重新安装MySQL即可

相关命令

启动MySQL服务:systemctl start mysqld.service
查看MySQL服务:systemctl status mysqld.service

此时如果要进入MySQL得找出root用户的密码,输入命令

grep "password" /var/log/mysqld.log
w&Qsi4IDu9e1

修改用户密码

# 登录MySQL
mysql -uroot -p
# 修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '5LNKrDtHsR7$';

如果提示错误:
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
则需要改用命令:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('5LNKrDtHsR7$');

授权外网访问

授权所有数据库权限:GRANT ALL ON *.* TO 'root'@'%';
本人测试过,使用 update user set host = '%' where user = 'root'; 也可以修改

创建其他账号

1. 创建用户

创建用户:CREATE USER 'admin'@'%' IDENTIFIED BY '5LNKrDtHsR7$';

2. 用户分配权限

授予用户通过外网IP对于该数据库“testdb”的全部权限

grant all privileges on testdb.* to 'admin'@'%' ;

# 刷新权限
flush privileges; 

其它问题


caching_sha2_password错误解决方案

如果使用客户端连接提示了plugin caching_sha2_password错误,这是因为MySQL8.0的密码策略默认为caching_sha2_password
使用命令修改策略
ALTER USER 'facebook'@'%' IDENTIFIED WITH mysql_native_password BY 'J5LNKrJ7DtHknsR7$';


降低密码安全策略

如果想设置密码为123456, 需要降低密码安全性策略

set global validate_password_policy=LOW
set global validate_password_length=6
alter user user() identified by '123456'
flush  privileges

你可能感兴趣的:(centosmysql)