mysql collection of methods to connect to a database remotely

  • 2020-05-06 11:50:13
  • OfStack

1, change the table method. It may be that your account is not allowed to log in remotely, only in localhost. At this point, just log in to mysql from the localhost computer and change the "host" item in the "user" table in the "mysql" database from "localhost" to "%"

 
mysql -u root -pvmwaremysql>use mysql; 
mysql>update user set host = '%' where user = 'root'; 
mysql>select host, user from user; 

2. Authorization. For example, if you want myuser to connect to an mysql server from any host using mypassword.
* TO 'myuser'@'%'IDENTIFIED 'BY 'mypassword' WITH GRANT OPTION *.
If you want to allow the user myuser to connect to the mysql server from the ip 192.168.1.6 host and use mypassword as the password
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3'IDENTIFIED BY
* 'mypassword WITH GRANT OPTION;
The first method I used, I found out at first that it didn't work. I looked it up on the Internet and executed one less statement mysql> FLUSH RIVILEGES
Make the change effective, and you're ready
3. Another method:
Run on the machine on which mysql is installed:
1, d: \ mysql \ bin \ > mysql -h localhost -u root
// this should allow access to MySQL server
2, mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION
// give any host access to the data 3, mysql> FLUSH PRIVILEGES
// modification effective
4, mysql> EXIT
// quit MySQL server
This allows you to log in as root on any other host.
If the above operation does not solve the problem, it may be the server's security Settings, is not ip security policy or firewall does not open 3306 exception.


Related articles: