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
Release: 2024-12-08 19:16:11
Original
413 people have browsed it

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:

1

SHOW GRANTS FOR root@localhost;

Copy after login

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:

1

GRANT ALL PRIVILEGES ON *.* TO 'root'@'host_or_subnet' IDENTIFIED BY 'password' WITH GRANT OPTION;

Copy after login

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:

1

FLUSH PRIVILEGES;

Copy after login
  1. Grant Access by IP or Subnet (Optional):

In cases where name resolution is unreliable, you can grant access by IP or subnet instead:

1

2

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.%' IDENTIFIED BY 'password' WITH GRANT OPTION;

FLUSH PRIVILEGES;

Copy after login
  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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template