1.mysql>grant all privileges on *.* to 'root'@'%' identified by 'root';
(%) 表示所有ip
第1个root表示账户
第2个root表示密码
2.mysql>flush privileges;
3.停止并重启mysql服务。
停止命令:service mysql stop
启动命令:service mysql start
查看状态:service mysql status
如果以上操作还是不能访问,那么应该是mysql没有允许远程访问。
修改配置文件:
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
将bind-address = 127.0.0.1注释掉(即在行首加#),如下:
代码如下:
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.1
本文介绍如何设置MySQL数据库的远程访问权限。首先通过SQL命令授予指定账户所有权限,并更新权限表。接着修改MySQL配置文件,取消仅限本地访问的设置,最后重启服务使更改生效。
1349





