yum安装MySQL8
yum仓库
yum localinstall https://repo.mysql.com//mysql80-community-release-el8-2.noarch.rpm
或者
wget -i -c https://dev.mysql.com/get/mysql80-community-release-el8-2.noarch.rpm
yum -y install mysql80-community-release-el8-2.noarch.rpm
yum安装MySQL
yum -y install mysql-community-server
如果提示以下错误
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
启动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'@'%' identified by '5LNKrDtHsR7$';
MySQL8提示
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
需要使用下面这种语法
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
转载自:https://segmentfault.com/a/1190000041844820