centos7
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
再次安装 mysql: #yum install mysql-community-server
5.配置 mysql 字符集
#vim /etc/my.cnf,在文件末尾加上:character-set-server=utf8

6.启动 mysql 服务
#service mysqld start
停止 mysql 服务:#service mysqld stop
7.查询首次安装随机密码
#grep ‘password‘ /var/log/mysqld.log |head -n 1

8.登陆数据库
#mysql –u root –p,输入上面查询的密码登陆
9.修改 root 密码
首次登陆进去会出现提示:
You must reset your password using ALTER USER statement before executing this statement.
(在执行此语句之前,必须使用 ALTE USER 语句重设密码。)
个人学习使用,所以密码设为:root,
alter user user() identified by "root";
但是会报 Your password does not satisfy the current policy requirements.(您的密码不符合当前的策略要求。)

首先,修改 mysql5.7 的默认密码策略:
1. set global validate_password_policy=0;(密码长度符合即可)

2. set global validate_password_length=1;(修改密码默认长度为最小值,即 4 位)

再次设置密码:alter user user() identified by "root";

exit; 退出,使用新密码登陆 mysql

10.远程访问
防火墙设置 mysql 端口白名单:#vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

重启防火墙,#service iptables restart
登陆 mysql 创建远程访问用户’root‘,密码为’root’:create user [email?protected]%‘ identified by ‘root‘;

评论