MySQL远程登录
- ubuntu下修改配置文件(路径如下),解除root登录地址绑定
/etc/mysql/my.cnf 或者 /etc/mysql/mysql.conf.d/mysqld.cnf file.
用符号#把如下行注释掉
bind-address = 127.0.0.1
修改后变成 #bind-address = 127.0.0.1
- 赋予用户远程登录权限
用root登陆本地server,键入一下命令:
grant all privileges on *.* to my_username@remote_ip identified by 'my_password' with grant option;
my_username: 远程登录用户名
remote_ip:被允许的远程计算机地址
my_password: 登录密码带引号
查询远程用户已经添加
use mysql;
select user, host from user;
因为添加的远程用户,该表会增加一行my_username
user | host |
---|---|
my_username | remote_ip |
localuser | localhost |
debian-sys-maint | localhost |
mysql.session | localhost |
mysql.sys | localhost |
root | localhost |
- 重启mysql服务
sudo service mysql restart
- 命令行登录
mysql -u my_username -h remote_ip -p