Mysql localhost != 127.0.0.1?
Understanding the Difference
When connecting to a MySQL database without specifying a host name or using 'localhost', unix mysqld utilizes sockets. However, using the IP address '127.0.0.1' as the host triggers network connections.
Impact on Privileges
This distinction becomes apparent in the GRANT system. By default, grants given to 'root'@'localhost' only apply to connections using sockets. To extend these privileges to connections with '127.0.0.1', you need to explicitly grant them to 'root'@'127.0.0.1'.
Granting ALL Privileges from ALL Hosts
To assign full privileges for the 'root' user from any host to all databases, use the following command:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Verifying Privileges
Confirming the updated privileges:
mysql -u root -h 127.0.0.1 -pzenoss -e "SHOW GRANTS;"
The result should now display grants for 'root'@'127.0.0.1' along with 'root'@'localhost'.
The above is the detailed content of MySQL `localhost` vs. `127.0.0.1`: Why Does It Matter for User Privileges?. For more information, please follow other related articles on the PHP Chinese website!