前言
Mysql配置允许远程访问
Mysql远程登录报错ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.x.x:3306' (61)
的解决方案
将账户设置为允许远程访问
修改账户的Host
- 将mysql数据库的
user
表中root
账户的Host
字段从localhost
改为%
1 2
| mysql> USE mysql; mysql> UPDATE user SET host='%' WHERE host='localhost';
|
刷新权限
1
| mysql> flush privileges;
|
查看是否修改成功
1
| mysql> SELECT host,user, password FROM user;
|
配置文件中注释仅本机访问的配置
- 注释
bind-address
和mysqlx-bind-address
/opt/homebrew/etc/my.cnf1 2
| # bind-address = 127.0.0.1 # mysqlx-bind-address = 127.0.0.1
|
MacOS使用brew安装的mysql配置
- 初始化Mysql配置时不要禁用root用户的远程登录
1
| mysql_secure_installation
|
1
| Disallow root login remotely? (Press y|Y for Yes, any other key for No) : No
|
为远程登录的用户创建账户
<username>
:用户名
<password>
:密码
<ip>
:允许访问Mysql服务的客户端IP地址
查看账户
1
| mysql> SELECT User,Host from mysql.user;
|
创建账户
1
| mysql> CREATE user '<username>'@'<ip>' identified by '<password>';
|
允许任何IP地址的客户端访问
1
| mysql> CREATE user '<username>'@'%' identified by '<password>';
|
修改账户
1
| mysql> RENAME user '<username_old>'@'<ip_old>' to '<username_new>'@'<ip_new>';
|
删除账户
1
| mysql> DROP user '<username>'@'<ip>';
|
远程登录
<username>
:用户名
<password>
:密码
<ip>
:Mysql服务器IP地址
<port>
:Mysql服务端口号
1
| mysql -u<username> -p<password> -h<ip> -P<port>
|
完成
CSDN——alphaTao
CSDN——冰冷的希望