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!