开启远程访问MySQL权限,允许远程访问
我们在自己电脑上远程登录数据库会遇到以下错误

原因是MySQL默认是不允许远程访问。如果我们要实现远程访问,就得要去修改远程服务器上MySQL的配置文件 mysqld.cnf 。
在远程服务器终端输入命令:

把 bind-address = 127.0.0.1 这行注释,再保存退出。重启MySQL服务:



我们回到自己电脑再次登录,又出现以下错误:

原因是安装MySQL时候root用户设置只允许本地登录。
登录mysql后,依次输入以下命令:

其中host表示主机,user表示用户,authentication_string表示加密后的密码。
我们可以看到root用户对应的host是localhost,表示root只允许在本地登录。
我们要想远程访问就得把localhost改成 %,一般我们不会修改root的设置,所以就创建一个新的用户用来远程访问。


我们再用新创建的用户登录就可以实现远程访问了。

作者:黑马程序员人工智能+Python培训学院
首发:http://python.itheima.com/