配置相关
- 监听公网ip,修改端口
- 创建host
- 授权root用户所有人可以登录
- 允许指定用户(user),ip(192.168.1.1)访问
1
2
3sudo vim /etc/mysql/my.cnf
port=3389
bind-address='0.0.0.0'
权限相关
1
2
3select user,host from user;
update user set host='%' where user='root';
flush privileges;
1
2GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Password' WITH GRANT OPTION;
flush privileges;
1
2GRANT ALL PRIVILEGES ON *.* TO 'user'@'192.168.1.1' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;
flush privileges;
初始化密码获取
mysql 5.7 会初始化密码,之前版本没有密码就可以直接登录,5.7必须要用密码了
1
2cat /var/log/mysqld.log |grep password # 一般都是在第一行
mysql -u root -p # 输入刚才获取的密码就可以登录了