I am working on ubuntu 18.04. My pycharm version is:
PyCharm 2022.1 (Community Edition) Build #PC-221.5080.212, built on April 12, 2022 Runtime version: 11.0.14.1+1-b2043.25 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Linux 4.15.0-175-generic GC: G1 Young Generation, G1 Old Generation Memory: 1972M Cores: 12
Current Desktop: ubuntu:GNOME
When I am trying to connect with mysql using the following program:
import pymysql
conn = pymysql.connect(host='localhost',
user='root',
password='',
database='db',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
cursor = db.cursor()
I am getting the following errors:
> File "/home/user/PycharmProjects/pythonProjectDB/main2.py", line 9,
> in <module>
> cursorclass=pymysql.cursors.DictCursor) File "/home/user/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/connections.py",
> line 353, in __init__
> self.connect() File "/home/user/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/connections.py",
> line 633, in connect
> self._request_authentication() File "/home/user/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/connections.py",
> line 907, in _request_authentication
> auth_packet = self._read_packet() File "/home/user/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/connections.py",
> line 725, in _read_packet
> packet.raise_for_error() File "/home/user/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/protocol.py",
> line 221, in raise_for_error
> err.raise_mysql_exception(self._data) File "/home/user/PycharmProjects/pythonProjectRev/venv/lib/python3.6/site-packages/pymysql/err.py",
> line 143, in raise_mysql_exception
> raise errorclass(errno, errval) pymysql.err.OperationalError: (1698, "Access denied for user 'root'@'localhost'")
My mysql version is:
mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.7.37-0ubuntu0.18.04.1 |
+-------------------------+
1 row in set (0.00 sec)
Created databases are:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db |
| menagerie |
| mysql |
| performance_schema |
| sys |
+--------------------+
Somebody please guide me.
Zulfi.
lThe traceback (read bottom-up) error "
raise errorclass(errno, errval) pymysql.err.OperationalError: (1698, "Access denied for user 'root'@'localhost'")
" says that local userroot
was denied access to the database server.Were you running your queries as
root
or withsudo
? Why. Don't be confused between the system manager accountroot
and the MySql "root" user.See
https://serverpilot.io/docs/how-to-access-mysql-with-the-mysql-root-user/
and readman mysql mysqld
.