Granting Remote Access to MySQL Server for Specific Users
In MySQL, when you create users, their access is typically limited to the local machine ('localhost'). However, you may need to grant permissions to access the database server from remote machines. This is especially useful if you have multiple workstations or servers that require access to the same database.
Granting Remote Access Using a Host Pattern
To grant remote access to a specific user, you can use the following syntax:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%.domain.com' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
In this example, '%.domain.com' represents any machine in the 'domain.com' network. This grants the specified user ('username') access to all databases ('.') with the provided password.
Granting Remote Access Using IP Address or Subnet
If you cannot use a host pattern due to name resolution issues, you can grant access using the IP address or subnet of the remote machine:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'192.168.1.%' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
In this example, '192.168.1.%' grants access to any machine with an IP address beginning with '192.168.1.'.
Note: It's important to be cautious when granting remote access to MySQL servers. Ensure that you only grant access to authorized users and limit their privileges to what is necessary.
The above is the detailed content of How to Securely Grant Remote Access to Your MySQL Server?. For more information, please follow other related articles on the PHP Chinese website!