1.下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2.安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
3.安装mysql
yum install mysql-community-server
4.设置开机启动
systemctl enable mysqld
systemctl daemon-reload
5.修改root本地登录密码
图片中红色框框中就是mysql随机生成的密码,复制到Enter password
处即可登录
service mysqld start //启动mysql服务
grep 'temporary password' /var/log/mysqld.log
![图片描述][1]
登录后修改mysql本地root密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword1!';
或者
mysql> set password for 'root'@'localhost'=password('MyNewPassword1!');
注意:
mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误
6.添加远程登录用户
为了账户安全起见建议新建账户用于远程登录,root
权限过高(本地登录)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'xinyonghu'@'%' IDENTIFIED BY 'XinYongHu123!' WITH GRANT OPTION;
7.配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'