Fix Can't connect to local MySQL server through socket error on CentOS 7 / RHEL 7 / Fedora 22

How to fix ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2 “No such file or directory”) error on CentOS 7 / RHEL 7 / Fedora 22 / SL 7 / OL 7. This type of error occured most of enterprise grade Linux Distributions the fix provides the solve this errors.

Pre Steps after occuring the MariaDB installations

Step-I (Install the MariaDB)
On Fedora 22
[email protected] ~ # dnf install mariadb
On CentOS 7 / RHEL 7 / OL 7 / SL 7
[email protected] ~ # yum install mariadb mariadb-server
Sample output
Last metadata expiration check performed 0:43:57 ago on Wed Aug 19 20:25:53 2015.
Dependencies resolved.
=====================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================
Installing:
mariadb x86_64 1:10.0.20-1.fc22 updates 6.1 M
mariadb-common x86_64 1:10.0.20-1.fc22 updates 73 k
mariadb-config x86_64 1:10.0.20-1.fc22 updates 25 k
mariadb-errmsg x86_64 1:10.0.20-1.fc22 updates 199 k
mariadb-libs x86_64 1:10.0.20-1.fc22 updates 636 k
mariadb-server x86_64 1:10.0.20-1.fc22 updates 18 M
perl-DBD-MySQL x86_64 4.031-1.fc22 fedora 151 k
perl-DBI x86_64 1.633-3.fc22 fedora 727 k

Transaction Summary
=====================================================================================================================================================
Install 3 Packages

Total download size: 6.2 M
Installed size: 38 M
Is this ok [y/N]: y
Downloading Packages:
(1/8): mariadb-config-10.0.20-1.fc22.x86_64.rpm 9.5 kB/s | 25 kB 00:02
(2/8): mariadb-common-10.0.20-1.fc22.x86_64.rpm 21 kB/s | 73 kB 00:03
(3/8): mariadb-10.0.20-1.fc22.x86_64.rpm 101 kB/s | 6.1 MB 01:01
(4/8): perl-DBD-MySQL-4.031-1.fc22.x86_64.rpm 6.4 kB/s | 151 kB 00:23
(5/8): perl-DBI-1.633-3.fc22.x86_64.rpm 27 kB/s | 727 kB 00:27
(6/8): mariadb-errmsg-10.0.20-1.fc22.x86_64.rpm 34 kB/s | 199 kB 00:05
(7/8): mariadb-libs-10.0.20-1.fc22.x86_64.rpm 62 kB/s | 636 kB 00:10
(8/8): mariadb-server-10.0.20-1.fc22.x86_64.rpm 82 kB/s | 18 MB 03:49

-----------------------------------------------------------------------------------------------------------------------------------------------------
Total 97 kB/s | 26.2 MB 01:05
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Installing : mariadb-config-1:10.0.20-1.fc22.x86_64 1/8
Installing : mariadb-common-1:10.0.20-1.fc22.x86_64 2/8
Installing : mariadb-1:10.0.20-1.fc22.x86_64 3/8
Installing : perl-DBI-1.633-3.fc22.x86_64 4/8
Installing : mariadb-libs-1:10.0.20-1.fc22.x86_64 5/8
Installing : perl-DBD-MySQL-4.031-1.fc22.x86_64 6/8
Installing : mariadb-errmsg-1:10.0.20-1.fc22.x86_64 7/8
Installing : mariadb-server-1:10.0.20-1.fc22.x86_64 8/8
Verifying : mariadb-1:10.0.20-1.fc22.x86_64 1/8
Verifying : mariadb-common-1:10.0.20-1.fc22.x86_64 2/8
Verifying : mariadb-config-1:10.0.20-1.fc22.x86_64 3/8
Verifying : mariadb-server-1:10.0.20-1.fc22.x86_64 4/8
Verifying : perl-DBD-MySQL-4.031-1.fc22.x86_64 5/8
Verifying : perl-DBI-1.633-3.fc22.x86_64 6/8
Verifying : mariadb-errmsg-1:10.0.20-1.fc22.x86_64 7/8
Verifying : mariadb-libs-1:10.0.20-1.fc22.x86_64 8/8

Installed:
mariadb.x86_64 1:10.0.20-1.fc22 mariadb-common.x86_64 1:10.0.20-1.fc22 mariadb-config.x86_64 1:10.0.20-1.fc22 mariadb-errmsg.x86_64 1:10.0.20-1.fc22 mariadb-libs.x86_64 1:10.0.20-1.fc22 mariadb-server.x86_64 1:10.0.20-1.fc22
perl-DBD-MySQL.x86_64 4.031-1.fc22 perl-DBI.x86_64 1.633-3.fc22

Complete!
Step-II (Runnig MySQL Command)
[email protected] ~ # mysql
 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")
Step-III (Checking the Mariadb Service)
[email protected] ~ # systemctl status mariadb
 ● mariadb.service - MariaDB 10.0 database server
 Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
 Active: inactive (dead)

How to fix this?

Step-I (Start the Mariadb service)
[email protected] ~ # systemctl start mariadb
Step-II (Auto enable the Service)

Service started automatically when Linux kernel is booted also add the service at systemd system and service managers.

[email protected] ~ # systemctl enable mariadb
 Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
Step-III (Verify whether services are stared or not)
[email protected] ~ # systemctl status mariadb
● mariadb.service - MariaDB 10.0 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2015-08-19 21:46:13 IST; 8s ago
Process: 18042 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 17903 ExecStartPost=/usr/libexec/mysql-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 17710 ExecStartPre=/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Process: 17680 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 17901 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─17901 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─18012 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/m...

Aug 19 21:46:12 localhost.localdomain mysql-prepare-db-dir[17710]: The latest information about MariaDB is available at http://mariadb.org/.
Aug 19 21:46:12 localhost.localdomain mysql-prepare-db-dir[17710]: You can find additional information about the MySQL part at:
Aug 19 21:46:12 localhost.localdomain mysql-prepare-db-dir[17710]: http://dev.mysql.com
Aug 19 21:46:12 localhost.localdomain mysql-prepare-db-dir[17710]: Support MariaDB development by buying support/new features from MariaDB
Aug 19 21:46:12 localhost.localdomain mysql-prepare-db-dir[17710]: Corporation Ab. You can contact us about this at [email protected]
Aug 19 21:46:12 localhost.localdomain mysql-prepare-db-dir[17710]: Alternatively consider joining our community based development effort:
Aug 19 21:46:12 localhost.localdomain mysql-prepare-db-dir[17710]: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
Aug 19 21:46:12 localhost.localdomain mysqld_safe[17901]: 150819 21:46:12 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Aug 19 21:46:12 localhost.localdomain mysqld_safe[17901]: 150819 21:46:12 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Aug 19 21:46:13 localhost.localdomain systemd[1]: Started MariaDB 10.0 database server.

Congratulations now you have enabled the Mariadb services.

Hot Right Now

Related Post

COMMENTS