Error connecting to MySQL: Can't connect to local MySQL server through socket

THN Data

Verified User
Joined
Jun 2, 2013
Messages
39
Hi all.

I have 3 VPS servers that i upgraded to Debian 8. 2 of them work like a charm but one is not feeling well.

I get this when accessing Mysql Management Error connecting to MySQL: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I have looked into /etc/my.cnf and the only thing i have in there is local-infile=0.

Mysql is running but causing some issues as above and I can't use create backups because it can't connect to the database.

My system looks like this.
Apache 2.4.18 Running
DirectAdmin 1.50.0 Running
Exim 4.86.2 Running
MySQL 5.6.29 Running
Named 9.8.4 Running
sshd Running
dovecot 2.2.22 (fe789d2) Running
pure-ftpd 1.0.42 Running
Php 5.6.19 Installed

How can i fix my messed up Mysql installation? I am also using Custombuild and have run the CB plugin with the Build All feature and everything seems to go through smoothly but no.

Best regards
Jukka
 
Last edited:
Thanks Alex.

If i run the 3 firs commands on the page.

server:~# ls -la /var/lib/mysql/mysql.sock
ls: cannot access /var/lib/mysql/mysql.sock: No such file or directory
server:~# netstat -lnp | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 523/mysqld
unix 2 [ ACC ] STREAM LISTENING 2617377089 523/mysqld /usr/local/mysql/data/mysql.sock
server:~# ps ax | grep mysql
253 ? Ss 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysqld.pid --socket=/usr/local/mysql/data/mysql.sock
523 ? Sl 0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/server.thndata.com.err --pid-file=/usr/local/mysql/data/mysqld.pid --socket=/usr/local/mysql/data/mysql.sock
8542 pts/0 S+ 0:00 grep mysql


Best regards
Jukka
 
Did you try to rebuild MySQL after Debian upgrade?

You've got MySQL running with socket /usr/local/mysql/data/mysql.sock. I don't have Debian 8 now to test it, so it might be a default place for mysql.sock on Debian 8.

If you rebuild MySQL after OS upgrade and still have socket in the place, then you might need to update my.cnf per this instruction

http://www.directadmin.com/features.php?id=140

Code:
socket=/usr/local/mysql/data/mysql.sock

and you might need update the same way /etc/my.cnf and rebuild PHP.

Not tested by me. So be careful.

p.s. I'd start with MySQL rebuild.
 
I have run .build all a couple of times. with the same result i have now.

I give it a go and see what happen if anything.

Thanks for taking your time to assist me.

Best regards
Jukka
 
Even if you've run build all it does not necessary mean that MySQL was rebuilt. What are the options?

Code:
./build options
 
This is the output.

server:/usr/local/directadmin/custombuild# ./build options
Apache: 2.4.18
mod_ruid2: 0.9.8
ModSecurity: no
Dovecot: 2.2.22
Dovecot configuration: yes
AWstats: 7.4
Exim: 4.86.2
exim.conf update: yes, release 4.3
BlockCracking: no
Easy Spam Fighter no
SpamAssassin: 3.4.1
ClamAV: 0.99.1
MySQL: 5.6.29
MySQL backup: yes
MySQL backup directory: /usr/local/directadmin/custombuild/mysql_backups
PHP (default): 5.6 as mod_php
phpMyAdmin: 4.6.0-all-languages
ProFTPD: no
Pure-FTPd: 1.0.42
RoundCube webmail: 1.1.4
Replace "php.ini" with './build all' and './build php_ini': no
Auto updates/notifications: no
Run "clean" every time: yes
Run "clean_old_webapps" every time: yes
Run "clean_old_tarballs" every time: yes
Show texts in bold: yes
SquirrelMail: 1.4.23-20150507_0200
Zend Guard Loader: no
ionCube loader: 5.0.20
Suhosin: no
 
If all my databases are backed up here: /usr/local/directadmin/custombuild/mysql_backups

Is there a way to download them to my computer?

// Juka
 
OK, custombuild is configured to build/upgrade MySQL. And was it really rebuilt?

Code:
ls -la `which mysql | grep bin/mysql | head -1`
 
OK, it seems to be correct, as the new default location on Debian is as you already pointed. Here is what build script has:

Code:
        if [ "${MYSQL_SOCK}" = "/tmp/mysql.sock" ] && [ "${SYSTEMD}" = "yes" ] && [ -e ${DEBIAN_VERSION} ]; then
[B]                MYSQL_SOCK=/usr/local/mysql/data/mysql.sock
[/B]        fi

Thus you should probably update my.cnf as it was suggested earlier.
 
Nopp. tryied again and get this output.

server:/usr/local/directadmin/custombuild# ./build mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) <--- So it i change this in my.cnf to the one above..
mv: 'mysql-5.6.29-linux-x86_64.tar.gz' and '/usr/local/mysql-5.6.29-linux-x86_64.tar.gz' are the same file
Stopping mysqld ...
Synchronizing state for mysqld.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d mysqld defaults
insserv: warning: script 'K01da-popb4smtp' missing LSB tags and overrides
insserv: warning: script 'K01mysqld' missing LSB tags and overrides
insserv: warning: script 'K01directadmin' missing LSB tags and overrides
insserv: warning: script is corrupt or invalid: /etc/init.d/../rc6.d/K00vzreboot
insserv: warning: script 'mysqld' missing LSB tags and overrides
insserv: warning: script 'da-popb4smtp' missing LSB tags and overrides
insserv: warning: script 'directadmin' missing LSB tags and overrides
insserv: warning: script 'named' missing LSB tags and overrides
Executing /usr/sbin/update-rc.d mysqld enable
update-rc.d: error: mysqld Default-Start contains no runlevels, aborting.
Backing up /usr/local/mysql/lib/libmysqlclient.so.16 to /usr/local/directadmin/custombuild/libmysqlclient.so.16
Ensuring local-infile is disabled for security reasons in MySQL configuration file...
Giving mysqld a few seconds to start up...
Looking for 'mysql' as: /usr/local/mysql/bin/mysql
Looking for 'mysqlcheck' as: /usr/local/mysql/bin/mysqlcheck
Running 'mysqlcheck with default connection arguments
Warning: Using a password on the command line interface can be insecure.
/usr/local/mysql/bin/mysqlcheck: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect
FATAL ERROR: Error during call to mysql_check for fixing the db/tables names on mysql db
Restarting MySQL.
 
If all my databases are backed up here: /usr/local/directadmin/custombuild/mysql_backups

Is there a way to download them to my computer?

1. gzip backups in /usr/local/directadmin/custombuild/mysql_backups
2. copy them into /home/admin or any other user of your own
3. download them either by FTP or HTTP

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) <--- So it i change this in my.cnf to the one above..

Yes, try to change socket= in /etc/my.cnf, /usr/local/directadmin/conf/mysql.conf and /usr/local/directadmin/conf/my.cnf
 
Great.

I only did it in /etc/my.cnf will di it on the rest to. And then build php again.
 
YES... Thanks a bunch Alex.

The web-pages run like running water and i can access the databases again.

Best regards
Jukka
 
Hmm i may have been cheering too soon..

I got this message when running backups of all the sites?

Error while backing up database admin_jom35dem
Error while backing up database admin_jom35dem: The sql file is 0 bytes in size: /home/admin/admin_backups/admin/backup/admin_jom35dem.sql
mysqldump error output: mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect

And if I download one of the databases through the MYSQL Management in Direct admin they are empty but the size column indicates that it is in 3.72 mb

// Jukka
 
How does /etc/my.cnf look like ?
Do you have /root/.my.cnf?
What you see if you run

Code:
mysql
?
 
My /etc/my.cnf loks like this

[mysqld]
local-infile=0
socket=/usr/local/mysql/data/mysql.sock

I do not have any /root/my.cnf

And running mysql give me this.
mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
 
It is /root/.my.cnf

As for /etc/my.cnf update it to the following view:

Code:
[mysql]
socket                         = [COLOR=#333333]/usr/local/mysql/data/mysql.sock[/COLOR]


[mysqld]
socket                         = [COLOR=#333333]/usr/local/mysql/data/mysql.sock[/COLOR]
[COLOR=#333333]local-infile                   = 0[/COLOR]

and restart mariadb/mysql.
 
Sorry a typo only on .my.cnf

I updated the /etc/my.cnf and restarted but now all pages are down.

server:~# /etc/init.d/mysqld restart
-e Stopping mysqld: [ FAILED ]
-e Starting mysqld: [ OK ]

// Jukka
 
Back
Top