Linux 5/ Drupal 7 / PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket

Hello, I need help please quickly..

everytime I try to connect to our website is giving me this error:

PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2) in lock_may_be_available() (line 167 of /data1/html/includes/lock.inc).

Any ideas why?
- MySQL seems not up..

Please help
poposkiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerCommented:
Check free disk space.

If that's not it (enough free space) then try:

mysqladmin -u root -p status

If it's not running , try changing your permission to mysql folder

sudo chmod -R 755 /var/lib/mysql/

Then restart mysql and check if it's running. Please note the mysql log file usually also reveals what the exact problem is.
poposkiAuthor Commented:
MySQL is running, databases are loaded, just checked and can not connect via website..



Error
 The website encountered an unexpected error. Please try again later.


Error message
 PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in lock_may_be_available() (line 167 of /data1/html/includes/lock.inc).. .
poposkiAuthor Commented:
Through "htop" I see the mysql is running and databases are loaded, but your sugestion to run:

mysqladmin -u root -p status

Says:
mysqladmin: connect to server at 'local host' failed
error" 'Can't connect to local MYSQL server through socket '/tmp/mysql.sock' (2)
Check that mysqld is running and that socket: '/tmp/mysql.sock' exists!

.... pleae help
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

KimputerCommented:
Post your my.cnf file?
poposkiAuthor Commented:
I cant even access the server throgh Putty SSH anymore (Server unexpected closed connection), but the Web Admin works I can access.. I can only the my.cnf through terminal

Give me a minute to get the file posted..
poposkiAuthor Commented:
my-cnf-1.pdf

I am sorry its in PDF format, but its the only way I can extrc the file...

Working on TXT format..
poposkiAuthor Commented:
Same in PDF but a bit clearrer..my-cnf-2b.pdf
poposkiAuthor Commented:
also file is missing

mysql.sock
poposkiAuthor Commented:
I did lots of research to find out how to recreate the mysql.sock. The file is missing and deleted on its own.

- I tried to re created by trying both ways:
chmod 1777 /tmp
chmod 4777 /tmp/mysql.stock

- than I found out it will self create once the SQL is restarted, so I deleted the mysql.stock by
rm -f /tmp/mysql.sock

- than I tried to re-start MySQL both ways by:
mysql restart
mysql* restart

- both gave me error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.stock' (2)

PLEASE HELP !!!!

2 things,

-I can connect to our App server RHL 5.0 via Webmin page http://192.168.1.4:10001/     : but not through SSH Putty..

- and if I try to restart/status of MySQL through webmin is showing :
Executing /etc/rc.d/init.d/mysql status ..
MySQL is running but PID file could not be found[FAILED]
poposkiAuthor Commented:
this is from mySQL process:

/usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/data2/mysqlvar --user=mysql --log-error=/data2/mysqlvar/App-server.err --open-files-limit=8192 --pid-file=/data2/mysqlvar/App-server.pid --socket=/tmp/mysql.sock --port=3306

- but defenetly can not find mysql.sock
KimputerCommented:
in the my.cnf file under the
[mysqld] header, put these two lines (they're almost the same, but I don't know which is the exact line your mysql install will interpret

pid_file=/tmp/mysql.pid
pid-file=/tmp/mysql.pid


then in the shell:

cd /tmp
touch mysqld.pid
chown mysql:mysql mysqld.pid

Try again to restart mysqld

Also post the last bits of the mysql error log if it doesn't work.

I also really have a bad feeling about your /data2, is there really enough space?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
poposkiAuthor Commented:
File system seems ok.. I will try your sugestions.. (I will post it soon if any errors)

Mounted as    Type    Location    Used    In use?    Saved?    

/ (Root filesystem) Linux Native Filesystem (ext3) LVM VG VolGroup00, LV LogVol00      -  50% Yes Yes
/tmp Linux Native Filesystem (ext3) LVM VG VolGroup00, LV LogVol01      -  5% Yes Yes
/data2 Linux Native Filesystem (ext3) LVM VG VolGroup00, LV LogVol08      -  32% Yes Yes
/home Linux Native Filesystem (ext3) LVM VG VolGroup00, LV LogVol05      -  84% Yes Yes
/var Linux Native Filesystem (ext3) LVM VG VolGroup00, LV LogVol03      -  19% Yes Yes
/usr Linux Native Filesystem (ext3) LVM VG VolGroup00, LV LogVol02      -  87% Yes Yes
/data1 Linux Native Filesystem (ext3) LVM VG VolGroup00, LV LogVol06      -  79% Yes Yes
/opt Linux Native Filesystem (ext3) LVM VG VolGroup00, LV LogVol04      -  9% Yes Yes
/boot Linux Native Filesystem (ext3) Partition labelled /boot      -  10% Yes Yes
/dev/shm RAM/Swap Disk (tmpfs) tmpfs      -  0% Yes Yes
/dev/pts Pseudoterminal Device Filesystem (devpts) devpts
 Yes Yes
/sys Kernel Filesystem (sysfs) sysfs
 Yes Yes
/proc Kernel Filesystem (proc) proc
 Yes Yes
Virtual Memory Virtual Memory (swap) LVM VG VolGroup00, LV LogVol07
 Yes Yes
/media/NAS Common Internet Filesystem (cifs) \\192.168.1.230\server_backup      -   74% Yes Yes
/media/mm Common Internet Filesystem (cifs) \\192.168.1.230\mailman_backup      -  74% Yes Yes
/media/share Common Internet Filesystem (cifs) \\192.168.1.230\share     -   74% Yes Yes
poposkiAuthor Commented:
I did exactly as you suggested and error remains the same:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.stock' (2)
KimputerCommented:
You said two times already:  '/tmp/mysql.stock' (2)

While the file should be SOCK. Is it only a typo? Or it's really stock (as the error you see on the screen)?
poposkiAuthor Commented:
sorry typo, just copied the typo..

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
KimputerCommented:
did you check the existence of /data2/mysqlvar/App-server.pid  or maybe /tmp/mysql.pid ?
Please post (or part of the end of) /data2/mysqlvar/App-server.err
poposkiAuthor Commented:
.. sorry for the delay (fire drill)

/tmp/mysql.pid       - (does exist)
/data2/mysqlvar/App-server.pid      (does NOT exist)

and looding App-server.err  (in few min..)
poposkiAuthor Commented:
wow, App-server.er - flooded with error msgs.. give me a minute to get it off the Linux box.. need to mount a USB and post it here.
poposkiAuthor Commented:
My App-server.err   App-server-err.txt

last few.. (full is attached as TXT file..

InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock /data2/mysqlvar/innodb/ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
150618  8:51:27  InnoDB: Unable to open the first data file
InnoDB: Error in opening /data2/mysqlvar/innodb/ibdata1
150618  8:51:27  InnoDB: Operating system error number 11 in a file operation.
InnoDB: Error number 11 means 'Resource temporarily unavailable'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/operating-system-error-codes.html
InnoDB: Could not open or create data files.
InnoDB: If you tried to add new data files, and it failed here,
InnoDB: you should now edit innodb_data_file_path in my.cnf back
InnoDB: to what it was, and remove the new ibdata files InnoDB created
InnoDB: in this failed attempt. InnoDB only wrote those files full of
InnoDB: zeros, but did not yet use them in any way. But be careful: do not
InnoDB: remove old data files which contain your precious data!
150618  8:51:27 Plugin 'InnoDB' init function returned error.
150618  8:51:27 Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
150618  8:51:27 Unknown/unsupported table type: InnoDB
150618  8:51:27 Aborting

150618  8:51:27 [Note] /usr/local/mysql/libexec/mysqld: Shutdown complete

150618 08:51:27 mysqld_safe mysqld from pid file /data2/mysqlvar/App-server.pid ended
KimputerCommented:
just to double check, please output the results for:

ls -l /tmp/mysql.pid
ls -l /tmp/mysql.sock
KimputerCommented:
Are you sure there are no other mysql services stuck (ps aux | grep mysql)? kill them all, then start again.

Otherwise, if possible, full server reboot.
poposkiAuthor Commented:
Also better view of my.cnf

 my-cnf.txt
poposkiAuthor Commented:
I have mounted databases, would killing everything will comprimise my databases?  (Using Drupal 7.0) Do I have to rebuild the database after?

ps aux | grep mysql

root      6433  0.0  0.0   2568  1032 ?        S    12:42   0:00 sh -c (ps aux | grep mysql) 2>&1
root      6434  0.0  0.0   2568   460 ?        S    12:42   0:00 sh -c (ps aux | grep mysql) 2>&1
root      6436  0.0  0.0   1956   524 ?        S    12:42   0:00 grep mysql
root     29158  0.0  0.0   2572  1124 ?        S    Jun05   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data2/mysqlvar --pid-file=/data2/mysqlvar/App-server.pid
mysql    29360 20.1 21.5 2716484 2689624 ?     SLl  Jun05 3741:43 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/data2/mysqlvar --user=mysql --log-error=/data2/mysqlvar/App-server.err --open-files-limit=8192 --pid-file=/data2/mysqlvar/App-server.pid --socket=/tmp/mysql.sock --port=3306


Also:
ls -l /tmp/mysql.pid   (does NOT exist)
ls -l /tmp/mysql.sock   (does NOT exist)

:.. What is the command to kill mySQL services again?  (sorry for the ignorence, just looking for the right way)


Thank you for everything
KimputerCommented:
killall mysqld_safe
killall mysqld

then restart the service (after double checking both are not in the ps aux list anymore)
poposkiAuthor Commented:
I did that, they are no longer in the list:

root  7228  0.0  0.0  4032   712  tty1     S+  13:35   0:00  grep mysql


previous I posted the wrong info:

wrong instence I posted, terminal was showing :

ps aux | grep mysql

root      7166  0.0  0.0    4032  708 tty1 S+  13:31   0:00 grep mysql
root      29158  0.0  0.0   2572   1124 ?        S    Jun05 0:00 /bin/sh  /usr/lcal/mysql/bin/mysqld_safe   --datadir=/data2/mysqlvar  --user=msql --log-error=/data2/mysqlvar/App-server.pid. err --open-files-limit=8192 --pid-fie=/data2/mysqlvar/App-server.pid --socket=/tmp/mysql.sock --port=3306

I tried again:
mysql start    

showing:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.stock' (2)
KimputerCommented:
So what happens now after you start the mysqld service?
poposkiAuthor Commented:
I tried again:
 mysql start    

showing:
 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
poposkiAuthor Commented:
ps aux | grep mysql

root  7228  0.0  0.0  4032   712  tty1     S+  13:35   0:00  grep mysql


this is how to start service ? :

mysql start    

showing:
 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
KimputerCommented:
kill all mysql processes again, then

touch  /tmp/mysql.pid
touch /tmp/mysql.sock  

then start mysql again.
poposkiAuthor Commented:
When I tried to'killall sql" and 'killall sqld', this time both showing:
mysql no process killed
mysqld no process killed

Than I did what you sugested:
touch  /tmp/mysql.pid
touch /tmp/mysql.sock  

 ----  Now has little different ERROR: -----

showing:
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
poposkiAuthor Commented:
I even changed permissions of 'mysql.sock' and 'mysql.pid'

chown mysql:mysql mysql.sock
chown mysql:mysql mysql.pid


than restarted:
mysql restart

showing:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)

-- wow, this problem is killing my time..  (thank you for your help..)
KimputerCommented:
check rights of all the files in  /data2/mysqlvar/innodb/, chown to to mysql if not already
poposkiAuthor Commented:
mysql - has full permissions
KimputerCommented:
do a badblocks command on the /data2 drive/partition
After it's been certified to not having badblocks, try to copy all the files in that folder to somewhere else (checking read integrity of the files)

Another thing you can do, delete ib_logfile0 and ib_logfile1 (find it in one of the folders we were working on before), then restart mysql
poposkiAuthor Commented:
All your help was very good, but the way the data base was wrapped was un-usual. The way the developer have created this site was needed to load it in aperticular fashion..

mysqld –user=mysql &’

That string was the only way the MySQL needed to be restarted.. I found this string in this refference:
https://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

But thank you soooo much. And appologies for not ending this in time..

Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.