Mysql local access is fine, but remote access is not. Mysql does not support remote access by default.

So how do you get remote access? Two conditions are indispensable:

Mysql itself should be allowed

1, set the existing account to support remote access to the newly installed mysql, only one account, is the administrator root, limited to the local access.

mysql>SELECT User, Host FROM mysql.user;
Copy the code
+------+-----------+
| user | host      |
+------+-----------+| root | 127.0.0.1 | | root | : : 1 | | root | localhost | +------+-----------+
3 rows in set (0.14 sec)
Copy the code

You can change host to ‘%’ so that all machines can access it.

mysql>update user set host = The '%' where user = 'root';
Copy the code

2. Creating an account that can be accessed remotely is of course a better way to create a new user, open to remote access. After all, root is the administrator and has too much authority.

mysql>create user 'test' identified by '123456'; mysql>grant all on db1.* to test@The '%';
Copy the code

Then find another machine to access: capital P followed by port, capital D followed by database name.

 C:\Users\Administrator> mysql -h 192.168. 0248. -P 3306 -D db1 -u test -p
Copy the code

Mysql server

It’s usually a firewall problem.

When mysql is installed, port 3306 is set to open to the public, but this is only open to the same domain, so if other machines in the LAN are not in the same domain, they still cannot connect. At this time also for the dedicated, public set as open: