title: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) on Lubuntu 20.04 LTS
body: <p>At first, I checked the correct installation of mysql on my <strong>Lubuntu 20.04 LTS system</strong>:</p>
  <pre><code>(scrapy_course) andylu@andylu-Lubuntu-PC:~/Desktop/Misc_python_scripts/Scrapy_Webscraping_Course/books_crawler$ sudo apt install mysql-server
  Reading package lists... Done
  Building dependency tree       
  Reading state information... Done
  mysql-server is already the newest version (8.0.22-0ubuntu0.20.04.3).
  0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
  </code></pre>
  <p>Next, I tried to connect to mysql:
  (scrapy_course) andylu@andylu-Lubuntu-PC:~/Desktop/Misc_python_scripts/Scrapy_Webscraping_Course/books_crawler$ sudo mysql -u root
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  (scrapy_course) andylu@andylu-Lubuntu-PC:~/Desktop/Misc_python_scripts/Scrapy_Webscraping_Course/books_crawler$ mysql -u root
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)</p>
  <p>When trying to stop <code>mysql</code> via <code>sudo systemctl stop mysql</code>, the terminal didn't respond for more than half a minute, but eventually stopped the process.
  Then, I executed <code>sudo systemctl restart mysql</code>, same waiting game for more than a minute or so.
  Finally, the following error message was displayed:</p>
  <pre><code>(scrapy_course) andylu@andylu-Lubuntu-PC:~/Desktop/Misc_python_scripts/Scrapy_Webscraping_Course/books_crawler$ sudo systemctl restart mysql
  Job for mysql.service failed because the control process exited with error code.
  See &quot;systemctl status mysql.service&quot; and &quot;journalctl -xe&quot; for details.
  </code></pre>
  <p>Checking on it right away, it says the following:</p>
  <pre><code>(scrapy_course) andylu@andylu-Lubuntu-PC:~/Desktop/Misc_python_scripts/Scrapy_Webscraping_Course/books_crawler$ systemctl status mysql.service
  ● mysql.service - MySQL Community Server
       Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
       Active: activating (start) since Sun 2020-12-06 17:46:48 CET; 30s ago
      Process: 18803 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
     Main PID: 18811 (mysqld)
       Status: &quot;Server startup in progress&quot;
        Tasks: 13 (limit: 9257)
       Memory: 244.7M
       CGroup: /system.slice/mysql.service
               └─18811 /usr/sbin/mysqld
  
  Dec 06 17:46:48 andylu-Lubuntu-PC systemd[1]: Starting MySQL Community Server...
  </code></pre>
  <p>And the other command to check printed out what follows:</p>
  <pre><code>(scrapy_course) andylu@andylu-Lubuntu-PC:~/Desktop/Misc_python_scripts/Scrapy_Webscraping_Course/books_crawler$ journalctl -xe
  -- The job identifier is 7118 and the job result is done.
  Dec 06 17:48:29 andylu-Lubuntu-PC systemd[1]: Starting MySQL Community Server...
  -- Subject: A start job for unit mysql.service has begun execution
  -- Defined-By: systemd
  -- Support: http://www.ubuntu.com/support
  -- 
  -- A start job for unit mysql.service has begun execution.
  -- 
  -- The job identifier is 7118
  </code></pre>
  <p>Apart from working with <code>MySQL</code> in the terminal, I have already installed the <code>python mysqlclient</code> like so:</p>
  <pre><code>sudo apt install default-libmysqlclient-dev
  pip install mysqlclient
  </code></pre>
  <p>Now, being in my <code>ipython</code>-shell, I tried to connect to my root <code>mySQL</code>-database like so, ending up with the same error as in the standard <code>bash</code> terminal:</p>
  <pre><code>Python 3.9.0 (default, Nov 22 2020, 23:12:14) 
  Type 'copyright', 'credits' or 'license' for more information
  IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
  
  In [1]: import MySQLdb
  
  In [2]: mydb = MySQLdb.connect(host='localhost', user='root', passwd='astralux13')
  ---------------------------------------------------------------------------
  OperationalError                          Traceback (most recent call last)
  &lt;ipython-input-2-8747acd85ff9&gt; in &lt;module&gt;
  ----&gt; 1 mydb = MySQLdb.connect(host='localhost', user='root', passwd='astralux13')
  
  ~/.virtualenvs/scrapy_course/lib/python3.9/site-packages/MySQLdb/__init__.py in Connect(*args, **kwargs)
      128     from MySQLdb.connections import Connection
      129 
  --&gt; 130     return Connection(*args, **kwargs)
      131 
      132 
  
  ~/.virtualenvs/scrapy_course/lib/python3.9/site-packages/MySQLdb/connections.py in __init__(self, *args, **kwargs)
      183         autocommit = kwargs2.pop(&quot;autocommit&quot;, False)
      184 
  --&gt; 185         super().__init__(*args, **kwargs2)
      186         self.cursorclass = cursorclass
      187         self.encoders = {k: v for k, v in conv.items() if type(k) is not int}
  
  OperationalError: (2002, &quot;Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)&quot;)
  </code></pre>
  <p>It seems like I can't get pass this error and don't know what to try else anymore.
  I intended to implement some of the top solutions posted in the following discussions with no avail:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run">ERROR 2002 (HY000): Can&#39;t connect to local MySQL server through socket &#39;/var/run/mysqld/mysqld.sock&#39; (2)</a></li>
  <li><a href="https://stackoverflow.com/questions/11990708/error-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysq">error: &#39;Can&#39;t connect to local MySQL server through socket &#39;/var/run/mysqld/mysqld.sock&#39; (2)&#39; -- Missing /var/run/mysqld/mysqld.sock</a>
  (<code>sudo find / -type s</code> didn't show my any opened mysql-sockets)</li>
  </ul>