1.配置yum源
# 下载mysql源安装包
# 安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
2.安装mysql
yum install mysql-community-server
3、启动MySQL服务
systemctl start mysqld
查看MySQL的启动状态
systemctl status mysqld
4、开机启动
systemctl enable mysqld
systemctl daemon-reload
5、修改root默认密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。
查看默认密码
grep 'temporary password' /var/log/mysqld.log
其中9I-adfVI-dRF 就是我的默认密码
用默认密码登录
修改默认密码
mysql> SET PASSWORD = PASSWORD('root'); # 上面的root是你的新密码
如何解决ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 呢? 这里直接提供解决方案文末有详细的说明
必须修改两个全局参数:
首先,修改validate_password_policy参数的值
mysql> set global validate_password_policy=0;
再修改密码的长度
set global validate_password_length=1;
再次执行修改密码就可以了
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
6.允许root远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1223456' WITH GRANT OPTION;
注释:此处root权限分配错误
上边设置的root密码是123456 此处分配权限的时候是1223456
需要从新分配权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
7.linux mysql授权远程连接
>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION
//任何主机访问数据的权限
例如,你想user使用password从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%'IDENTIFIED BY 'password' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用password作为密码
GRANT ALL PRIVILEGES ON *.* TO 'user'@'192.168.1.3'IDENTIFIED BY 'password' WITH GRANT OPTION;
>FLUSH PRIVILEGES 、
//停数据库 systemctl stop mysqld
//重启数据库 systemctl restart mysqld