MySQL connection by 127.0.0.1
Good afternoon!
Installed the MySQL DBMS on Mac OS X. Localhost connects to databases normally, but how to make it connect to 127.0.0.1? There is a user with such a host in mysql.
Where can I set this up?
2 answers
There are two ways to connect to a MySQL server: via a socket and via a network. When you write localhost as a host, the default connection goes through a socket, and when you write an IP address, it goes through a network. Therefore, there are also two solutions.
Enable network connection reception
To establish a network connection to the MySQL server, make sure that it is enabled. To do this, you should find the my.cnf configuration file (in Windows, my. ini) and in the [mysqld] section, you need to uncomment or create the following directives
[mysqld]
...
# Включаем сетевое соединение
skip-networking
# Разрешаем соединение только для локального хоста
bind-address = 127.0.0.1
After restarting the server, you will turn on the network interaction mode and you will be able to access through 127.0.0.1, and not through localhost.
Explicitly specify a socket when establishing a connection
Or, if you want to continue communication via the socket, when specifying 127.0.0.1 as the host, you must additionally pass the --socket
parameter in which to pass the path to the socket file (you can specify it in my.cnf)
mysql -h 127.0.0.1 -u root -p --socket=/var/run/mysqld/mysqld.sock
Faced with a similar problem, it was solved by editing the php.ini file, it is necessary to set the mysql.default_socket parameter in it https://digital-planet.info/viewtopic.php?f=84&p=1473