python3使用Django架構串連mysql(python3+Django+MySQL+pymysql)

來源:互聯網
上載者:User

標籤:other   read   root   https   named   version   ken   ges   databases   

改掉系統預設的sqlite3資料庫,

# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
‘default‘: {
# ‘ENGINE‘: ‘django.db.backends.sqlite3‘,
‘ENGINE‘: ‘django.db.backends.mysql‘,
# ‘NAME‘: os.path.join(BASE_DIR, ‘db.sqlite3‘),
‘NAME‘:‘djangoDB‘,
‘USER‘:‘root‘,
‘PASSWORD‘:‘123456‘,
‘port‘:‘3306‘,
}
}

然後啟動報錯,

ImportError: No module named ‘MySQLdb‘

據說要裝MySQL-python

可是MySQL-python一直無法安裝成功。

又報錯ImportError: No module named ‘ConfigParser‘

因為python3中叫做configparser,是小寫。

好吧,聽說不用MySQL-python可以用pymsql代替,然後就趕緊下載pip install pymysql

然後再啟動,還是不行啊,還是ImportError: No module named ‘MySQLdb‘

百度了下,看這篇文章http://www.jianshu.com/p/82781add8449

加了之後就好了。

這裡說下MySQL-python吧。

MySQL-python的解釋看官方說法

MySQLdb is an interface to the popular MySQL database server for Python. The design goals are:

  • Compliance with Python database API version 2.0 [PEP-0249]
  • Thread-safety
  • Thread-friendliness (threads will not block each other)

MySQL-3.23 through 5.5 and Python-2.4 through 2.7 are currently supported. Python-3.0 will be supported in a future release. PyPy is supported.

說白了就是串連mysql的python介面,有了他就可以用python來操作資料庫了。類似java的JDBC那一套東西把。

 

python3使用Django架構串連mysql(python3+Django+MySQL+pymysql)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.