Mysql error in erpnext

Mysql error while logging in to root user in erpnext

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

What are you trying to do?

trying to restart the mysql

Its not starting and my erpnext site is not working

So what command did you run?

service mysql restart

yes i run this command but it is not starting the mysql

mysqld failed while starting

I tried to login into the mysql server

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

I am facing this issue

It is difficult to guess without any logs. Also, it also a bit off topic for this forum.

I got the same error when i checked in mysql error logs

But erpnext will work thorugh mysql right

Please give details of this command:

netstat -tan | grep 3306

Try to see your /var/log/mysql if nothing displays there activate the log in of mysql server and check.



It is displaying some mariadb error logs


Please check whether mysql is really installed (or half installed) because the mysql socket is not created in the specified directory.
Launch this command:

Check if my mysql is running by service mysql status
Otherwise, do an apt-get install mariadb-server. If needed do a apt-get --purge remove mariadb-server before.
Hope it helps


1 Like

see actually i have error in brower

502 Bad Gateway
nginx/1.4.6 (Ubuntu)

What i am thinking is its a problem with mysql server.

When i tried to restart the mysql it is not starting, and i tried ur steps but it not helped me, i have a data in my server, so tell what i have to do now

I have the same issue…

ERPNext was running OK for months and suddenly MariaDB can’t start.

Have you solved it? how?

hi all,

I just have another problem related to mysql in database socket.

I need to setup my mariadb database as multiple instances by mysqld_multi. So the socket file is not in standard as /var/run/mysqld/mysqld.sock, it is another file name, eg. /var/run/mysqld/mysqld1.sock. After i setup my database and restart erpnext, i found it has a error in:

File "/home/easystore/frappe-bench/apps/frappe/frappe/", line 106, in sql
File "/home/easystore/frappe-bench/apps/frappe/frappe/", line 52, in connect
    use_unicode=True, charset='utf8')
File "/home/easystore/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/", line 81, in Connect
    return Connection(*args, **kwargs)
File "/home/easystore/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/", line 193, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2002, 'Can\'t connect to local MySQL server through socket \'/var/run/mysqld/mysqld.sock\' (2 "No such file or directory")')'

My solution is:

  1. adding a item into site_config.json as

    “db_unix_socket”: “/var/run/mysqld/mysqld3306.sock”,

  2. editing ~/frappe-bench/apps/frappe/frappe/

    class Database:

    def init(self, host=None, user=None, password=None, ac_name=None, use_default = 0):

    self.password = password or frappe.conf.db_password
    self.value_cache = {}

             self.unix_socket = frappe.conf.db_unix_socket or None

    def connect(self):
    “”“Connects to a database as set in site_config.json.”“”
    warnings.filterwarnings(‘ignore’, category=MySQLdb.Warning)
    self._conn = MySQLdb.connect(user=self.user,, passwd=self.password,
    use_unicode=True, charset=‘utf8’, unix_socket=self.unix_socket)

  3. start erpnext again, then it works.

1 Like

Thanks This Worked For Me. :slight_smile:

If you have used ERPNext, and liked it, then please help us spread the word by submitting your reviews on the following sites.

We as a community can achieve lot more than as individuals.