在这里,我们将给大家分享关于如何在Windows的Python3中连接到MySQL?的知识,让您更了解python怎么连接数据库的本质,同时也会涉及到如何更有效地Python2.7–在Windows8
在这里,我们将给大家分享关于如何在Windows的Python 3中连接到MySQL?的知识,让您更了解python 怎么连接数据库的本质,同时也会涉及到如何更有效地Python 2.7 – 在Windows 8上安装MySQL-Python错误、python – 在Windows 7机器上安装PyMySQL、Python 不能连接到MySQL ?、Python-如何使用Python连接到MySQL数据库?的内容。
本文目录一览:- 如何在Windows的Python 3中连接到MySQL?(python 怎么连接数据库)
- Python 2.7 – 在Windows 8上安装MySQL-Python错误
- python – 在Windows 7机器上安装PyMySQL
- Python 不能连接到MySQL ?
- Python-如何使用Python连接到MySQL数据库?
如何在Windows的Python 3中连接到MySQL?(python 怎么连接数据库)
我在Windows上使用ActiveState Python
3,并想连接到我的MySQL数据库。我听说那mysqldb
是要使用的模块。我找不到mysqldb
Python 3。
有二进制文件存在的存储库mysqldb
吗?如何在Windows上的Python 3中连接到MySQL?
Python 2.7 – 在Windows 8上安装MySQL-Python错误
我已经在这个2天的时间里撞到了我的头上,并且没有取得进展。
我正在尝试在我的Windows 8(恨Windows 8)框上安装Python MysqL连接器。
我正在使用Python 2.7。 我原来收到一个错误:
找不到vcvarsall.bat。
我怎样才能find每个线程在哪个处理器上运行?
C#事件日志不可访问的日志
grunt-contrib-build“不在npmregistry中
如何移动或调整X11窗口(即使它们被最大化)?
C – 在内存中创build文件
我做了一些调查,发现我需要在我的盒子上安装VS 2008(VC ++编译器),我安装了快速版本。 我还将ProductDir值与vcvarsall.bat的path添加到我的registry中的以下项:
HKEY_LOCAL_MACHInesOFTWAREWow6432NodeMicrosoftVisualStudio9.0SetupVC.
我还添加了VS90COMNTOOLS环境variables与vcvarsall.bat的path。 我运行以下命令时仍然出现错误:
pip install MysqL-python
您可以提供的任何input是非常感谢…谢谢…
该错误在pip.log的以下片段中列出:
Traceback (most recent call last): File "<string>",line 1,in <module> File "c:userstappdatalocaltemppip_build_TMysqL-pythonsetup.py",line 21,in <module> setuptools.setup(**Metadata) File "C:Python27libdistutilscore.py",line 152,in setup dist.run_commands() File "C:Python27libdistutilsdist.py",line 953,in run_commands self.run_command(cmd) File "C:Python27libdistutilsdist.py",line 972,in run_command cmd_obj.run() File "buildbdist.win-amd64eggsetuptoolscommandinstall.py",line 53,in run File "C:Python27libdistutilscommandinstall.py",line 563,in run self.run_command('build') File "C:Python27libdistutilscmd.py",line 326,in run_command self.distribution.run_command(command) File "C:Python27libdistutilsdist.py",in run_command cmd_obj.run() File "C:Python27libdistutilscommandbuild.py",line 127,in run self.run_command(cmd_name) File "C:Python27libdistutilscmd.py",in run_command cmd_obj.run() File "buildbdist.win-amd64eggsetuptoolscommandbuild_ext.py",line 52,in run File "C:Python27libdistutilscommandbuild_ext.py",line 337,in run self.build_extensions() File "C:Python27libdistutilscommandbuild_ext.py",line 446,in build_extensions self.build_extension(ext) File "buildbdist.win-amd64eggsetuptoolscommandbuild_ext.py",line 186,in build_extension File "C:Python27libdistutilscommandbuild_ext.py",line 496,in build_extension depends=ext.depends) File "C:Python27libdistutilsmsvc9compiler.py",line 473,in compile self.initialize() File "C:Python27libdistutilsmsvc9compiler.py",line 383,in initialize vc_env = query_vcvarsall(VERSION,plat_spec) File "C:Python27libdistutilsmsvc9compiler.py",line 299,in query_vcvarsall raise ValueError(str(list(result.keys()))) ValueError: [u'path'] ---------------------------------------- Cleaning up... Removing temporary dir c:userstappdatalocaltemppip_build_T... Command C:Python27python.exe -c "import setuptools,tokenize;__file__='c:\users\t\appdata\local\temp\pip_build_T\MysqL-python\setup.py';exec(compile(getattr(tokenize,'open',open)(__file__).read().replace('rn','n'),__file__,'exec'))" install --record c:userstappdatalocaltemppip-d5hmns-recordinstall-record.txt --single-version-externally-managed --compile Failed with error code 1 in c:userstappdatalocaltemppip_build_TMysqL-python Exception information: Traceback (most recent call last): File "C:Python27libsite-packagespip-1.5.4-py2.7.eggpipbasecommand.py",line 122,in main status = self.run(options,args) File "C:Python27libsite-packagespip-1.5.4-py2.7.eggpipcommandsinstall.py",line 283,in run requirement_set.install(install_options,global_options,root=options.root_path) File "C:Python27libsite-packagespip-1.5.4-py2.7.eggpipreq.py",line 1435,in install requirement.install(install_options,*args,**kwargs) File "C:Python27libsite-packagespip-1.5.4-py2.7.eggpipreq.py",line 706,in install cwd=self.source_dir,filter_stdout=self._filter_install,show_stdout=False) File "C:Python27libsite-packagespip-1.5.4-py2.7.eggpiputil.py",line 697,in call_subprocess % (command_desc,proc.returncode,cwd)) InstallationError: Command C:Python27python.exe -c "import setuptools,'exec'))" install --record c:userstappdatalocaltemppip-d5hmns-recordinstall-record.txt --single-version-externally-managed --compile Failed with error code 1 in c:userstappdatalocaltemppip_build_TMysqL-python
查找function区button的窗口句柄
如何在Windows上使用单声道运行时在Xamarin Studio中进行debugging
如何检查是否“所有人”具有完全控制权限的文件在c#
UWP:无法访问Licenseinformation
在Windows中的静态HTML
pip install失败表明有一些对编译文件的依赖。 另一种方法是使用https://pypi.python.org/pypi/MysqL-python中的.exe安装程序 – 但这不适用于virtualenvs,并且对于64位Python将会失败(它会抱怨它即使已安装,也无法在注册表中找到Python 2.7)。
幸运的是,Christoph Gohlke保留了一些非官方的Windows可执行文件。 你可以在http://www.lfd.uci.edu/~gohlke/pythonlibs/#MysqL-python找到它们
您现在可以从主Python环境或virtualenv中调用pip install C:/PATH/TO/MysqL_python‑1.2.5‑cp27‑none‑win_amd64.whl 。
理想情况下,像这样的车轮将通过MysqL-python PyPI页面提供,在这一点上,一个简单的pip install将工作。
(这个答案是基于Carsten的有用的评论。)
python – 在Windows 7机器上安装PyMySQL
我不是python用户,虽然我使用过MySQL,但我不是专家.另外,我主要是一个Windows用户,我对运行命令行脚本了解不多.所以这可能是一个愚蠢的问题,但无论如何我想问…
(BTW我的目的是安装’棒球棒’)
我安装了Python(Windows 7机器上的3.3版本).
接下来它说要安装pyMysqL.所以我从https://github.com/petehunt/PyMySQL/下载了.zip文件
自述文件说“只需从本地目录运行build-py3k.sh脚本.它将在./py3k目录中构建一个工作包.”我完全不知道这意味着什么.我该怎么办?我尝试在Python命令行界面中键入它,它只是给了我一个错误.
有一些非常明确的指示,并在运行python 3.3的Windows 8上为我工作
在这里拉链:
http://www.summet.com/dmsi/html/codesamples/pymysql3.zip
Python 不能连接到MySQL ?
用Python写了一个数据库管理的小程序,但是出现不能连接到MySQL的问题,百度之也未能解决,请问要如何做?
系统:Windows7 64bit
语言:Python 2.7
数据库:Mysql 5.0
错误提示:
OperationalError: (2003, "Can''t connect to MySQL server on ''localhost'' (10061)")
连接数据库的代码
#coding=utf-8 import MySQLdb conn = MySQLdb.connect( host=''localhost'', port=3306, user=''root'', passwd=''cityfmsd'', db=''test'', ) cur = conn.cursor()
Traceback (most recent call last): File "C:\Users\LinlinLee\Desktop\pythondb.py", line 9, in <module> db=''test'', File "E:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect return Connection(*args, **kwargs) File "E:\Python27\lib\site-packages\MySQLdb\connections.py", line 193, in __init__ super(Connection, self).__init__(*args, **kwargs2) OperationalError: (2003, "Can''t connect to MySQL server on ''localhost'' (10061)")
MySQL服务已经正常开启
MySQL commend line client 可以正常的连接到数据库
Python-如何使用Python连接到MySQL数据库?
如何解决Python-如何使用Python连接到MySQL数据库??
分三步使用Python 2连接到MysqL
在执行任何操作之前,必须安装MysqL驱动程序。与PHP不同,默认情况下,Python仅安装sqlite驱动程序。最常用的软件包是MysqLdb,但很难使用easy_install
进行安装。请注意,MysqLdb仅支持Python 2。
对于Windows用户,你可以获取MysqLdb的exe。
对于Linux,这是一个临时包(python-MysqLdb
)。(你可以在命令行中使用sudo apt-get install python-MysqLdb
(对于基于debian的发行版),yum install MysqL-python
(对于基于rpm的dnf install python-MysqL
发行版)或(对于现代的fedora发行版)进行下载。)
对于Mac,你可以使用Macport安装MysqLdb。
安装后,重新启动。这不是强制性的,但是如果出现问题,它将阻止我回答本文中的3或4个其他问题。因此,请重新启动。
然后就像使用其他任何软件包一样:
#!/usr/bin/python
import MysqLdb
db = MysqLdb.connect(host="localhost", # your host, usually localhost
user="john", # your username
passwd="megajonhy", # your password
db="jonhydb") # name of the data base
# you must create a Cursor object. It will let
# you execute all the queries you need
cur = db.cursor()
# Use all the sql you like
cur.execute("SELECT * FROM YOUR_TABLE_NAME")
# print all the first cell of all the rows
for row in cur.fetchall():
print row[0]
db.close()
当然,有成千上万种可能性和选择。这是一个非常基本的例子。你将不得不查看文档。一个良好的起点。
一旦知道了它的工作原理,你可能希望使用ORM来避免手动编写sql并像处理Python对象一样处理表。Python社区中最著名的ORM是sqlAlchemy。
我强烈建议你使用它:你的生活将变得更加轻松。
我最近在Python世界中发现了另一件珠宝:peewee。这是一个非常精简的ORM,设置起来非常简单快捷。对于小型项目或独立应用程序来说,这让我感到欣慰,而在使用sqlAlchemy或Django等大型工具的情况下,这太过残酷了:
import peewee
from peewee import *
db = MysqLDatabase(''jonhydb'', user=''john'', passwd=''megajonhy'')
class Book(peewee.Model):
author = peewee.CharField()
title = peewee.TextField()
class Meta:
database = db
Book.create_table()
book = Book(author="me", title=''peewee is cool'')
book.save()
for book in Book.filter(author="me"):
print book.title
本示例开箱即用。除了带有peewee(pip install peewee)外,没有其他要求。
解决方法
如何使用python程序连接到MySQL数据库?
今天关于如何在Windows的Python 3中连接到MySQL?和python 怎么连接数据库的讲解已经结束,谢谢您的阅读,如果想了解更多关于Python 2.7 – 在Windows 8上安装MySQL-Python错误、python – 在Windows 7机器上安装PyMySQL、Python 不能连接到MySQL ?、Python-如何使用Python连接到MySQL数据库?的相关知识,请在本站搜索。
本文标签: