當前位置:首頁 » 編程語言 » pythoninstallmysql

pythoninstallmysql

發布時間: 2023-06-03 18:08:26

python安裝pymysql【MAC】

1、輸入「python3 install pymysql",報錯:

2、後來使用國內鏡像源,還是報錯,無法安裝。

    pip3 install 庫名 -i 鏡像源地址

    例如:pip3 install pymysql -i  https://pypi.tuna.tsinghua.e.cn/simple

    鏡像源地址

    清華: https://pypi.tuna.tsinghua.e.cn/simple

    豆瓣: http://pypi.douban.com/simple/

    阿里: http://mirrors.aliyun.com/pypi/simple/

3、經網上查詢,需使用」--trusted-host  pypi.tuna.tsinghua.e.cn ",可安裝成功。

即:pip install 庫名 -i 鏡像源地址 --trusted-host  pypi.tuna.tsinghua.e.cn

例如:pip3 install pymysql -i https://pypi.tuna.tsinghua.e.cn/simple --trusted-host pypi.tuna.tsinghua.e.cn

4、驗證pymysql是否安裝成功。

>>>import pymysql   不報錯就行。

㈡ Python之MySQL操作

MySQL 是目前使用最廣泛的資料庫之一,它有著良好的性能,能夠跨平台,支持分布式,能夠承受高並發。下載地址: MySQL :: Download MySQL Community Server 安裝參考: 圖解MySQL5.7.20免安裝版配置方法-網路經驗 (.com)

Python 大致有如下 5 種方式操作 MySQL。

先使用如下建表語句創建一張簡單的資料庫表。

2.1 mysqlclient

執行 pip install mysqlclient 進行安裝,看一下具體操作。

新增

查詢

cursor 查看方法

修改

刪除

2.2 PyMySQL

執行 pip install pymysql 進行安裝,使用方式與 mysqlclient 基本類似。

2.3 peewee

執行 pip install peewee 進行安裝,看一下具體操作。

定義映射類

新增

查詢

修改

刪除

2.4 SQLAlchemy

執行 pip install sqlalchemy 進行安裝,看一下具體操作。

定義映射類

新增

查詢

修改

刪除

Python學習日記

㈢ centos7下Python調用mysql

python要調用mysql首先要安裝python 的mysql模塊,centos下可以通過以下方法來安裝:

  1. 直接yum安裝

    yum install MySQL-python -y

  2. 通過pip安裝

    pip install mysql-python

查看是否安裝成功,運行python,在python終端裡面運行

import MySQLdb

如果沒有報錯說明安裝成功,然後就可以連接你的數據了

  1. 創建一個資料庫的連接

connect = MySQLdb.connect(host='127.0.0.1',user='user',passwd='password',db='db')

2.獲取資料庫的游標

cor = connect.cursor()

3.執行一個SQL語句

cor.excute("select * from user;")

4.獲取SQL的結果

for row in cor.fetchall():

print row

5.關閉連接

connect.close()

㈣ python3.4怎麼連接mysql pymysql連接mysql資料庫

到python官方網站下載最新python程序。根據系統有32,64位。
直接下一步,就可以安裝成功。
win7系統下python3.4連接mysql資料庫
在python官網中去下載ez_setup.py文件。
此工具是python管理包工具,通過它可以下載很多服務。
請根據系統下載相關文件。
win7系統下python3.4連接mysql資料庫
在python中執行python ez_setup.py文件,如果沒有配置環境變數,可以在python安裝路徑中找到python.exe,在此目錄中執行上面命令。
命令執行成功後,會在python安裝目錄下easy_install.exe工具包。
win7系統下python3.4連接mysql資料庫
win7系統下python3.4連接mysql資料庫
在CMD命令行執行:easy_install.exe pymysql3
如果找不到該命令,切換服務到python安裝目錄/Scripts/下執行。如果此目錄下沒有easy_install.exe,證明上一步沒有安裝成功。
安裝pymysql3服務如下。
win7系統下python3.4連接mysql資料庫
pymysql3服務安裝成功後,開始寫python程序連接mysql服務。
mysql資料庫安裝在此省略,到mysql官方網站下載,下一步安裝就可以了。
win7系統下python3.4連接mysql資料庫
python程序內容如下:import pymysql
conn = pymysql.connect(user='root', passwd='root',
host='localhost', db='zjctest')
cur = conn.cursor()
cur.execute("SELECT * FROM zjc")
for r in cur:
print("row_number:" , (cur.rownumber) )
print("id:"+str(r[0])+"name:"+str(r[1])+"age:"+str(r[2]))
cur.close()
conn.close()
win7系統下python3.4連接mysql資料庫
7
執行結果如下,證明連接mysql資料庫成功,且數據正確返回。
win7系統下python3.4連接mysql資料庫

㈤ 在Python虛擬環境中使用環境外的mysql

與環境沒有什麼關系。包名錯掉了。你想裝的應該是 mysql-connector-python-rf,這個不依賴mysql C client. 另一個常用的是 MySQL-python,這個需要依賴mysql C client.

㈥ python mysqldb 安裝問題

mysqldb只有python2.5版的,2.6的需要額外的東東,我也記不清了,不過有人把2.6對應的東東弄成一個exe了,直接運行就裝上了,也不需要額外配置啥的,你留個郵箱啥的,我給你傳過去吧。

import MySQldb?
還是MySQLdb?
l要大寫L.
另外:_mysql.pyd是在python安裝目錄\Lib\site-packages下的

㈦ Python2.7安裝mysql-python報錯,求教

# script to register python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/procts/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/[email protected]/msg10512.html

import sys

from _winreg import *

# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix

regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
installpath, installpath, installpath
)

def RegisterPy():
try:
reg = OpenKey(HKEY_CURRENT_USER, regpath)
except EnvironmentError as e:
try:
reg = CreateKey(HKEY_CURRENT_USER, regpath)
SetValue(reg, installkey, REG_SZ, installpath)
SetValue(reg, pythonkey, REG_SZ, pythonpath)
CloseKey(reg)
except:
print "*** Unable to register!"
return
print "--- Python", version, "is now registered!"
return
if (QueryValue(reg, installkey) == installpath and
QueryValue(reg, pythonkey) == pythonpath):
CloseKey(reg)
print "=== Python", version, "is already registered!"
return
CloseKey(reg)
print "*** Unable to register!"
print "*** You probably have another Python installation!"

if __name__ == "__main__":
RegisterPy()

熱點內容
如何評價一個伺服器的性能 發布:2025-05-17 23:40:53 瀏覽:270
淘寶客適合什麼伺服器 發布:2025-05-17 23:39:26 瀏覽:612
python循環文件 發布:2025-05-17 23:39:22 瀏覽:828
androidstudio更新 發布:2025-05-17 23:38:22 瀏覽:643
java項目面試 發布:2025-05-17 23:30:53 瀏覽:780
若主存儲器按位元組編址 發布:2025-05-17 23:30:46 瀏覽:24
kotlinandroid 發布:2025-05-17 23:19:09 瀏覽:974
雲編程英語 發布:2025-05-17 23:18:34 瀏覽:623
androidstudio導入類 發布:2025-05-17 23:15:36 瀏覽:237
私人電腦伺服器如何設置 發布:2025-05-17 23:14:48 瀏覽:366