pythoninstallmysql
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下可以通过以下方法来安装:
直接yum安装
yum install MySQL-python -y
通过pip安装
pip install mysql-python
查看是否安装成功,运行python,在python终端里面运行
import MySQLdb
如果没有报错说明安装成功,然后就可以连接你的数据了
创建一个数据库的连接
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()