If you can connect to MySQL locally, why can't I connect to MySQL remotely? This is because the default installation of MySQL, for security reasons, can only be locally connected. If you need to connect remotely, you need to set up MySQL's permissions table here. The following steps are set up:
1. Connect MySQL natively in MySQL.
2. Execute the following MySQL command:
Use MySQL #打开mysql数据库
#将host设置为% means that any IP can be connected to MySQL, but you can also designate host as an IP
Update user set host= '% ' where user= ' root ';
Flush privileges; #刷新权限表 for the configuration to take effect
Then we can connect to our MySQL remotely.
3, if you want to close the remote connection, restore the default MySQL settings (only local connection), you can do the following steps:
Use MySQL #打开mysql数据库
#将host设置为localhost表示只能本地连接mysql
Update user set host= ' localhost ' where user= ' root ';
Flush privileges; #刷新权限表 for the configuration to take effect
Note: You can also add a user named Yuancheng, with a password of 123456, and a permission of% (indicating that any IP can connect) to a remote connection user. The command reference is as follows:
Grant all on * * to ' yuancheng ' @ ' percent ' identified by ' 123456 ';
Flush privileges;