CentOS7下安装mysql8
1.下载rpm包
https://dev.mysql.com/downloads/repo/yum/
2、安装rpm包
#rpm -ivh mysql80-community-release-el7-3.noarch.rpm
3、安装mysql服务
#yum install mysql-server
#systemctl start mysqld.service #启动服务
#systemctl status firewalld.service #查看防火墙状态
#systemctl stop firewalld.service #关闭防火墙
4、查看默认密码
sudo grep 'temporary password' /var/log/mysqld.log
5、添加新用户并授权
-- 在[mysqld]下加入skip-grant-tables进入数据库
#vim /etc/my.conf
-- mysql8添加新用户并授权
create user '用户名'@'localhost' identified by '新密码'; grant all privileges on mysql.user to '用户名'@'localhost' with grant option; flush privileges;
-- mysql8默认的密码策略可能会影响登陆验证,刷新为原来的
ALTER user '用户名'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码'; #修改加密规则 ALTER user '用户名'@'localhost' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER; #更新一下用户的密码且不过期 flush privileges;#刷新权限
-- 查询数据库用户列表
select host, user, authentication_string, plugin from user;
-- 最后删掉#skip-grant-tables,重启服务
#systemctl restart mysqld.service
-- 如果提示无法创建数据库,修改mysql配置文件/etc/my.conf修改sql_mode值,然后重启服务即可
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION