一、配置TCP服务地址绑定
- 配置文件路径
/etc/mysql/mysql.cnf
/etc/mysql/mysql.conf.d/mysqld.cnf
具体文件可以通过 mysql --help查看
-
配置项
# 只接受本地连接 bind-address = 127.0.0.1 mysqlx-bind-address = 127.0.0.1
改为
# 接受任意IP地址连接 bind-address = 0.0.0.0 mysqlx-bind-address = 0.0.0.0
-
重启mysql服务
sudo systemctl restart mysql
- 查看结果
netstat -nao | grep 3306
二、账号与权限
- 创建账号
CREATE USER 'cbuser'@'myhost.example.com' IDENTIFIED BY 'cbpassword';
cbuser:用户账号
myhost.example.com:主机,表示想从哪台电脑连接到MySQL服务器。【%表示任意】
cbpassword:用户账号密码
- 权限
GRANT ALL ON cookbook.* TO 'cbuser'@'myhost.example.com';
FLUSH PRIVILEGES;
cookbook.* :数据库cookbook中的所有项【*.*表示所有数据库】
三、远程登陆
mysql -h 192.168.2.153 -u cbuser -p