官網操作教程:http://www.runoob.com/python3/python3-mysql.html
1、簡介
PyMySQL 是在 Python3.x 版本中用於連接 MySQL 服務器的一個庫,Python2中則使用mysqldb。
PyMySQL 遵循 Python 數據庫 API v2.0 規范,並包含了 pure-Python MySQL 客戶端庫。
2、PyMySQL安裝
在使用 PyMySQL 之前,我們需要確保 PyMySQL 已安裝。
PyMySQL 下載地址:https://github.com/PyMySQL/PyMySQL。
如果還未安裝,我們可以使用以下命令安裝最新版的 PyMySQL:
pip3 install PyMySQL
出現錯誤,提示需要更新pip
更新pip:
pip install --upgrade pip
繼續安裝PyMySQL:
pip3 install PyMySQL
出現以下錯誤的話,重啟就好了:
sudo reboot
這個時候一直卡在Building wheels for collected package:cryptography, cffi, pycparser。
解決辦法參考:
解決安裝PyMySQL一直停在Building wheels for collected package:cryptography, cffi, pycparser的問題
過程也是心酸
再次執行安裝PyMySQL:
pip3 install PyMySQL
大功告成!!!