yum仓库
yum localinstall https://repo.mysql.com//mysql80-community-release-el8-2.noarch.rpm
【yum安装MySQL8】或者
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
如果提示以下错误
Last metadata expiration check: 0:02:05 ago on Thu 18 Nov 2021 08:19:27 PM CST.
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
mysql -uroot -p
# 修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '5LNKrDtHsR7$';
创建用户 创建用户:
CREATE USER 'admin'@'%' IDENTIFIED BY '5LNKrDtHsR7$'
;
允许远程连接:
GRANT ALL ON *.* TO 'testdb'@'%'
;
本人测试过,使用
update user set host = '%' where user = 'root';
也可以修改用户分配权限 --授予用户通过外网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 spy_fb.* to 'facebook'@'%' ;
grant all privileges on spy_logs.* to 'facebook'@'%' ;
grant all privileges on spy_task.* to 'facebook'@'%' ;
# 刷新权限
flush privileges;
如果使用客户端连接提示了plugin caching_sha2_password错误,这是因为MySQL8.0的密码策略默认为caching_sha2_password
使用命令修改策略
ALTER USER 'facebook'@'%' IDENTIFIED WITH mysql_native_password BY 'J5LNKrJ7DtHknsR7$';