At the heart of most content management systems lies a database, such as MySQL, where the majority of content is stored. So for your pages to fully load, your website needs to be able to fetch the necessary information from the database at a moment’s notice. If for some reason a connection to the database cannot be established, you may see an error such as “Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock”. In this article, we will explore what is causing this problem and how to fix it.

What Does the PHP Warning “mysql_connect() can’t connect to mysql server” Mean?

If your website shows a message that it cannot connect to the local MySQL server through a socket, then the connection settings that you have entered are probably incorrect or incomplete. Double-checking these settings is very likely to fix this issue.

An example of the “mysql_connect() can’t connect to mysql server” warning can be seen below:

If your website has trouble connecting to its database, it may display an error message similar to this one.
If your website has trouble connecting to its database, it may display an error message similar to this one.

How Can I Fix the “Can’t Connect to Local MySQL Server Through Socket” Error?

First and foremost, you need to head to the Database Manager section of our Control Panel and click on the database that you are trying to connect to. From there, click on the Information tab.

The information tab will provide you with all credentials necessary to successfully connect to your MySQL database.
The information tab will provide you with all credentials necessary to successfully connect to your MySQL database.

In the Information tab, you will find your Database Host, Database Port, Database Name, Database User, Database Version, and Database Storage Engine. Compare this information to the database settings in your website configuration file and make changes where necessary. If you are not sure what password is assigned to your database, you can reset it from the Password tab in the Database Manager. Additional help with connecting your website to your database, including sample connection code, can be found in our article on where to find the database connection settings.

The Database Manager will be available to you if you are using our free hosting, premium shared hosting or one of the Semi-Dedicated web server plans. You can read our in-depth walkthrough of the Database Manager to familiarize yourself with all of the features this section of our Control Panel has to offer.

If you