Home >Database >Mysql Tutorial >How to Grant Remote Access to the MySQL Root User?

How to Grant Remote Access to the MySQL Root User?

Barbara Streisand
Barbara StreisandOriginal
2024-12-08 19:16:11414browse

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:

  1. Identify the Current Privileges:

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.

  1. Grant Access to Specific Hosts or Subnets:

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.%).

  1. Flush Privileges:

After granting the new permissions, execute the following query to apply them:

FLUSH PRIVILEGES;
  1. Grant Access by IP or Subnet (Optional):

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;
  1. Reference Documentation:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn