Home >Database >Mysql Tutorial >How to Grant Remote Access to the MySQL Root User?
Remote Access Permissions for MySQL Server: Granting Root User Access
Remote access to a MySQL server allows users to connect and interact with the database from machines outside the localhost environment. By default, the root user is only authorized to access the server from the local machine.
To grant remote access permissions to the root user, follow these steps:
Connect to the MySQL server and execute the following query:
SHOW GRANTS FOR root@localhost;
This will display the current access privileges granted to the root user.
If you want to grant access to specific hosts or subnets, use the following syntax:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'host_or_subnet' IDENTIFIED BY 'password' WITH GRANT OPTION;
Replace host_or_subnet with the hostname, IP address, or subnet mask (e.g., %.example.com or 192.168.1.%).
After granting the new permissions, execute the following query to apply them:
FLUSH PRIVILEGES;
In cases where name resolution is unreliable, you can grant access by IP or subnet instead:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.%' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUSH PRIVILEGES;
For further details, refer to the MySQL GRANT syntax documentation.
The above is the detailed content of How to Grant Remote Access to the MySQL Root User?. For more information, please follow other related articles on the PHP Chinese website!