this is somewhat of a mystery to me. The only way I can connect to MySQL is if I call it via "127.0.0.1" ... for example, my PHP connect script will NOT work with localhost
I'm running Mac OS X Lion, built-in apache2, MySQL, PHP, phpMyAdmin
mysqladmin:
count 0
debug-check FALSE
debug-info TRUE
force FALSE
compress FALSE
character-sets-dir (No default value)
default-character-set auto
host (No default value)
no-beep FALSE
port 0
relative FALSE
socket (No default value)
sleep 0
ssl FALSE
ssl-ca (No default value)
ssl-capath (No default value)
ssl-cert (No default value)
ssl-cipher (No default value)
ssl-key (No default value)
ssl-verify-server-cert FALSE
user (No default value)
verbose FALSE
vertical FALSE
connect-timeout 43200
shutdown-timeout 3600
plugin-dir (No default value)
default-auth (No default value)
MySQL will try to connect to the unix socket if you tell it to connect to "localhost". If you tell it to connect to 127.0.0.1 you are forcing it to connect to the network socket. So probably you have MySQL configured to only listen to the network socket and not to the file system socket.
What exactly is wrong with your unix socket is hard to tell. But I recommend you to read this page on the MySQL reference guide. This should help you.
UPDATE: Based on the updated question: The parameter "socket" should be something like this: "/var/lib/mysql/mysql.sock". This page in the Reference Manual has some more information.
Here you have the beginning of my /etc/my.cnf file:
Your file should be similar. Then your problem should be solved. Don't forget to restart the MySQL server before you test it.
You may have IPv6 enabled, its very possible localhost resolves to the ipv6 localhost, that is not defined in your msql config.
ive also had a problem where i had to add 'localhost' in place of '127.0.0.1' to the allowed subnets for that user, dont understand why (i was using ipv4 and it was a while ago) but its worth a try.
For me, OSX's builtin php is configured to use a different unix-socket than homebrew's mysql. Thus it can't connect via localhost which utilizes that socket.
I fixed it with a quick hack by symlinking php's configured socket-path to point to the one mysql actually uses.
The following diagnostic commands were very helpful.
Check the default socket-paths used by php and mysql:
Connect using a specified socket:
Determine what kind of socket mysql client is using to connect:
Could you check
mysql/conf/my.conf
(the directory structure should pretty much be the same on OSx) to see ifskip-networking
is uncommented? If so, add a#
in-front of the line and restart the mysql-server.I actually had a similar issue a while back (although that wasn't in OSx), so I thought it might be worth a shot.
PHP is still trying to use the default socket location. This problem can appear if you have moved the MariaDB/MySQL folder from /var/lib/mysql to another location. In order to solve the problem you have to define the new socket's location in the /etc/php.ini file.
Watch out, depending on which driver you use, you may have to specify the pdo_mysql.default_socket=!
In order to check your current directory run the following command in mysql:
For people who are using CageFS with CloudLinux:
I recreated
/var/lib/mysql
because I was rebuilding MySQL server from scratch...which unmounted the path from cagefs. I know it's unrelated, but I was using cPanel and CloudLinux. I couldn't verify why socket connection won't work, and finally, I realized.
adding
/var/lib/mysql
to/etc/cagefs/cagefs.mp
(if already there proceed to next step) and runningfixed the problem
Is localhost defined in your
/private/etc/hosts
file?I was able to recreate your same symptoms on my test box, hopefully this will help.
In MySQL, users are defined by two parts (name and host). By default, MySQL will have 3 root users:
The password field will either be blank (no password) or have a hash stored. If you set the password for one specific user, it doesn't automatically update all, since MySQL sees them as different users.
For example:
will update the password for
'root'@'127.0.0.1'
, but not'root'@'localhost'
or'root'@'localhost.localdomain'
Take a look at the
skip_name_resolve
variable:By Default
skip_name_resolve
isOFF
, and will attempt to resolve all IP Addresses to hostnames. For example, if you connect as'root'@'127.0.0.1'
, MySQL will change connect you as'root'@'localhost'
.If it is
ON
, MySQL will see and connect'root'@'127.0.0.1'
and'root'@'localhost'
as seperate users. And they may or may not have different passwords, depending on how they were set.So first, I would check to see any password differences:
mysql> SELECT host,user,password FROM mysql.user WHERE user='root';
If there are, you can fix them, or you can continue investigating.
Then I would check
skip_name_resolve
:mysql> show variables like 'skip_name_resolve';
If it is
ON
, I would find out where it's being set (for example/etc/my.cnf
) and remove it, unless there is a need for it.Hopefully this helps you out!
I was having this issue and I could not figure it out. I tried everything I could fine to no avail.
I found that I had a .netrc in /root/ that had info in it.
I deleted it and problem gone.
Able to log into mysql using mysql -uroot -p without issue now.
I know this is an old post but hope this helps someone.
For me, changing the permissions to be publically readable on the parent directory of the mysql.sock fixed the issue: