In my newly created django project, I configured MySQL connection instead of default sqlite3. When I ran python manage.py runserver
, I receive access denied error:
The Django complains wrong user&password, but I think both are correct as I repeatedly login mysql cli console with both. Any tips and suggestion for these access denied
appreciated.
Following are some backgrounds.
The python is 3.9 in ubuntu22.04. The django project is newly created, and I use pymysql
instead of mysqlclient for mysql operation. Therefore, I only made two changes:
- init pymysql
import pymysql
pymysql.version_info=(1,4,3,"final",0)
pymysql.install_as_MySQLdb()
- Configure the MySQL connection info
- I also tried the same in the python console, and shows the user&password should be ok.
>>> import pymysql
>>> conn = pymysql.connect(
... host='localhost',
... user='test',
... password = "test",
... db='xxx',
... )
>>> conn
<pymysql.connections.Connection object at 0x7f065c51ebe0>
>>> cur = conn.cursor()
>>> cur
<pymysql.cursors.Cursor object at 0x7f065ccd0ee0>
>>> cur.execute("select @@version")
1
>>> output = cur.fetchall()
>>> print(output)
(('8.0.32-0ubuntu0.22.04.2',),)
>>> conn.close()