error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'

vpscanban

Verified User
Joined
Feb 9, 2022
Messages
39
Hi all.
I got an error when building MariaDB. I am using DirectAdmin v.1.663 and reinstalled MariaDB 10.4 but am getting the following error. I reinstalled with the following commands

perl -pi -e 's/mysqld=ON/mysqld=OFF/' /usr/local/directadmin/data/admin/services.status
service mysqld stop
rm -rf /var/lib/mysql
cd /usr/local/directadmin/custombuild
./build clean
./build set mariadb 10.4
./build set mysql_inst mariadb
./build mariadb
 

Attachments

  • CleanShot 2024-05-28 at 20.07.30.png
    CleanShot 2024-05-28 at 20.07.30.png
    397.6 KB · Views: 561
[root@hosting ~]# systemctl status mysqld
● mysqld.service - MySQL database server
Loaded: loaded (/etc/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2024-05-28 21:40:08 +07; 45min ago
Process: 66922 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 66886 ExecStartPre=/bin/sh -c [ ! -e /usr/local/mysql/bin/galera_recovery ] && VAR= || VAR=`cd /usr/local/mysql/bin/..; /usr/local/mysql/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
Process: 66885 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 66908 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 14 (limit: 100337)
Memory: 66.1M
CGroup: /system.slice/mysqld.service
└─66908 /usr/local/mysql/bin/mysqld --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock
Why you wipe MySQL data directory?

systemctl status mysqld
It still works, but I can't access the root user.[root@hosting ~]# cat /usr/local/directadmin/conf/mysql.conf
user=da_admin
passwd=XXXXXXXXXXXXXXXXXXXXXX
[root@hosting ~]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@hosting ~]#
 
Last edited by a moderator:
Is this Debian by any chance? Had same issue with Debian before.
I fixed it by removing everything from mysql, and then checkt apt, removed mysql-common or mariadb-common (or something like that) from apt which was installed via apt and then installed mysql/mariadb again via custombuild.

However, be sure to have a backup of databases to begin with.
 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Wrong /etc/my.cnf ? Or duplicated installations?

According to the details from your post the MySQL socket is located under: /var/lib/mysql/mysql.sock
 
Is this Debian by any chance? Had same issue with Debian before.
I fixed it by removing everything from mysql, and then checkt apt, removed mysql-common or mariadb-common (or something like that) from apt which was installed via apt and then installed mysql/mariadb again via custombuild.

However, be sure to have a backup of databases to begin with.
No, I use Almalinux 8.8
 
which mysql

dnf list installed | grep mysql

find /usr /opt -name mysql -type f
 
There are 2 files my.cnf and I deleted it and rebuilt mariadb.
The 2 my.cnf you showed are both normal. First one contains the password for Directadmin, the second one, the /etc/my.cnf is to put in your own settings if necessary, so they are both valid.
 
Back
Top