Connect with us

Hi, what are you looking for?

Linux

How to Fix cannot connect to local MySQL server through socket error on CentOS 7

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 / SL 7 / OL 7. This type of error occurred 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
root@techbrown ~ # dnf install mariadb
On CentOS 7 / RHEL 7 / OL 7 / SL 7
root@techbrown ~ # yum install mariadb mariadb-server
Step-II (Runnig MySQL Command)
root@techbrown ~ # 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)
root@techbrown ~ # 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)
root@techbrown ~ # 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.

root@techbrown ~ # 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)
root@techbrown ~ # 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 sales@mariadb.com.
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.

Advertisement. Scroll to continue reading.
Comments
Advertisement
Advertisement

Linux

DNF stands Dandified YUM and this is the default package manager for RHEL 8 / CentOS 8.  This tutorial explains you how to create...

Linux

If you forget a root password of your RHEL 8 and CentOS 8 and want to reset the password so that the RHEL 8...

Windows

How to auto upgrade JioFi firmware for JioFi 2 / JioFi 3 / JioFi 4 / JioFi 5 / JioFi 6 and other JioFi...

Linux

How to Upgrade WordPress Server from Ubuntu 16.04 to Ubuntu 18.04. Right now, Ubuntu 18.04 has been released with tons of new features. Upgrading...

Linux

How to Enable TLS 1.3 on Nginx Web Server. Nginx is a ultra fast web server optimized for modern web applications and servers. TLS...

Advertisement

You May Also Like

Windows

How to auto upgrade JioFi firmware for JioFi 2 / JioFi 3 / JioFi 4 / JioFi 5 / JioFi 6 and other JioFi...

Windows

How to download and install the Mobile Intel 4 Series Express Chipset Graphics Drivers for Windows 10.  Windows 10 is the one of the...

Windows

Internet is the most important public network for connecting to the WEB. For internet connection requirement the ISP is required as well as it...

Windows

How to Install and Configure PCSX2 on Windows 10. The Windows 10 is the most recommended operating system for the Games. In stream platform...