Home >Database >Mysql Tutorial >How to Enable MySQL Root Access from All Hosts?

How to Enable MySQL Root Access from All Hosts?

DDD
DDDOriginal
2024-12-04 07:47:14850browse

How to Enable MySQL Root Access from All Hosts?

Enabling MySQL Root Access from All Hosts

You have defined the root user in the MySQL user table with access restricted to specific hosts. To allow root access from any host on the internet, follow these steps:

Step 1: Grant Privileges

As the root user, execute this query, replacing 'password' with your current password:

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

Step 2: Bind to All Interfaces

a) Open the MySQL configuration file (my.cnf):

sudo nano /etc/mysql/my.cnf

b) Locate the line containing:

# bind-address = 127.0.0.1

c) Remove the leading # (hash) character to comment out the line.

d) Restart MySQL:

sudo service mysql restart

By default, MySQL binds to localhost only. Commenting out the bind-address line will cause it to bind to all interfaces, effectively allowing access from any host.

Verification

To check the current MySQL binding, execute:

sudo netstat -tupan | grep mysql

You should see an entry with a bind address of 0.0.0.0:3306, indicating that MySQL is now listening on all interfaces.

The above is the detailed content of How to Enable MySQL Root Access from All Hosts?. 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