0

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: Access denied

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:

  1. init pymysql

Code sample

import pymysql                                                                                                 
pymysql.version_info=(1,4,3,"final",0)
pymysql.install_as_MySQLdb()   
  1. Configure the MySQL connection info

MySql cli sample and Database config in setting.py

  1. 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()

shijie xu
  • 1,975
  • 21
  • 52

0 Answers0