At first, I checked the correct installation of mysql on my Lubuntu 20.04 LTS system:
(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.
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)
When trying to stop mysql
via sudo systemctl stop mysql
, the terminal didn't respond for more than half a minute, but eventually stopped the process.
Then, I executed sudo systemctl restart mysql
, same waiting game for more than a minute or so.
Finally, the following error message was displayed:
(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 "systemctl status mysql.service" and "journalctl -xe" for details.
Checking on it right away, it says the following:
(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: "Server startup in progress"
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...
And the other command to check printed out what follows:
(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
Apart from working with MySQL
in the terminal, I have already installed the python mysqlclient
like so:
sudo apt install default-libmysqlclient-dev
pip install mysqlclient
Now, being in my ipython
-shell, I tried to connect to my root mySQL
-database like so, ending up with the same error as in the standard bash
terminal:
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)
<ipython-input-2-8747acd85ff9> in <module>
----> 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
--> 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("autocommit", False)
184
--> 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, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
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:
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
- error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' -- Missing /var/run/mysqld/mysqld.sock
(
sudo find / -type s
didn't show my any opened mysql-sockets)