Home > Database > Mysql Tutorial > body text

MySQL `localhost` vs. `127.0.0.1`: Why Does It Matter for User Privileges?

DDD
Release: 2024-11-23 20:24:11
Original
520 people have browsed it

MySQL `localhost` vs. `127.0.0.1`: Why Does It Matter for User Privileges?

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

Verifying Privileges

Confirming the updated privileges:

mysql -u root -h 127.0.0.1 -pzenoss -e "SHOW GRANTS;"
Copy after login

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template