How could it be? And main question - how to grant ALL privileges on ALL databases from ALL hosts for root?
UPD:
Nov 17, 2017 Seems like changing locahost with 127.0.0.1 fixes the error, at least in my configuration. If it doesn’t i would look for errors in tcp sockets connection and of course post it as a bug in pymysql.
UPD2:
Bunyk
BunykBunyk
4,2493 gold badges24 silver badges50 bronze badges
4 Answers
As you can see here, a UNIX mysqld uses sockets if used without a host name or with the host name
localhost
.
So it makes a difference, and in the GRANT system this difference becomes evident.
glglglglglgl
69.4k7 gold badges99 silver badges169 bronze badges
I know this tread is old, however was most probably not correctly answered.
By default, mysql does a name resolve so 127.0.0.1 and localhost will resolve in the same. However, you can switch the name resolution off in my.cnf:
skip-name-resolve = 1
Then localhost and 127.0.0.1 will NOT be the same anymore. So you either keep the name resolution, or restrict yourself to only using localhost in your grants or only 127.0.0.1BUT: If you do the latter one, you will have to access our database with those credentials as well.
Ingo RatsdorfIngo Ratsdorf
Log in through 127.0.0.1 and execute this statement:
You will probably see something like
I just confirmed on my local install and it seems MySQL won't auto-resolve the host name. You can either add another grant for
Matt DodgeMatt Dodge
localhost
or just use 127.0.0.1
8,2633 gold badges29 silver badges49 bronze badges
This caused issues in setting up a local dev environment on MacOS.
Several script functions, say
mysqli_connect()
in php might be using localhost
to connect to MySQL: You can't (shouldn't have to) go about replacing localhost
with 127.0.0.1
in every script.
Tried fixing this by adding
bind-address=localhost
, socket=/var/mysql/mysql.sock
, socket=/tmp/mysql.sock
etc. to the my.cnf file, but that didn't work.
![Mysql Mysql](/uploads/1/2/5/0/125060828/180926775.png)
To resolve the issue (on MacOS), note that the
mysql.default_socket
setting in /etc/php.ini
file points to /var/mysql/mysql.sock
, while MySQL's default_socket is /tmp/mysql.sock
.
So, either edit your
php.ini
file, or create a softlink to MySQL's default_socket:
P.S - 127.0.0.1 is treated as a TCP connection and localhost as unix socket connection by MySQL: details here.
Nitin NainNitin Nain