Learning Python is having problems connecting to MySQL Database
Install MySQL First:
Toolbar ===>file ==> default Settings==>project interpreter ==> Click on the + sign on the right Pymysql==>ok
(1) Enter settings.py==>
DATABASES = {
' Default ': {
' ENGINE ': ' Django.db.backends.mysql ',
' NAME ': ' Pymysql_test ',
' USER ': ' Root ',
' PASSWORD ': ' 123456 ',
' HOST ': ' localhost ',
' PORT ': ' 3306 ',
}
}
Then error message: Modulenotfounderror:no module named ' MySQLdb '
(2) View blog: http://www.cnblogs.com/zqifa/p/python-3.html
Turns out to be incompatible with the problem:
1. Import the PYMYSQ package in the _init_.py under the project folder
Import Pymysql
Pymysql.install_as_mysqldb ()
2. Set up Database in settings.py
DATABASES = {
' Default ': {
' ENGINE ': ' Django.db.backends.mysql ',
' NAME ': ' dbname ',
' USER ': ' DbUser ',
' PASSWORD ': ' Dbpwd ',
' HOST ': ', #默认本地
' PORT ': '
}
}
No module named ' mysqldb ' python3.6 + Django 1.10 + MySQL cannot connect