davispuh
2010-08-30
It's more than a year since python 3 was released, but there aren't any lib...
I searched but found nothing.. (actually I found
mypysql, but it doesn't compile
for win)
every time someone says that want use mysql in py3k he receives answer: "do
you really need python 3? use python 2.6"
thats NOT a solution, just easiest workaround...
some time I used mysql.php (self-made php script) it accepts post query and
returns xml result (it can be used in any language that have http and xml
support)
but this is just another workaround...
I got tired of these workarounds and so I ported MySQL-python-1.2.3 to python
3, it works fine and passes both tests (dbapi20 and capabilities) without any
errors... (I little modified tests to work in py3k)
here it is MySQL-python-1.2.3-py3k
feel free to use but "This program comes with ABSOLUTELY NO WARRANTY"
I removed most of python 2 stuff so it's only for py3k
I tested it with python 3.1 and mysql 5.1 on win32 (it should work on any
platform where MySQL-python-1.2.3 works)
It should work and have same functionally like original MySQL-python-1.2.3 for
python 2
just remember it's py3k and some things are different...
files I edited:
MySQLdb__init__.py
MySQLdb\connections.py
MySQLdb\converters.py
MySQLdb\cursors.py
tests\capabilities.py
tests\dbapi20.py
tests\test_MySQLdb_capabilities.py
tests\test_MySQLdb_dbapi20.py
_mysql.c
_mysql_exceptions.py
setup.py
setup_common.py
setup_posix.py
setup_windows.py
site.cfg (only changed 5.0 to 5.1)
I didn't remove any files and didn't add others too...
this is open source so if you find a bug then fix it and upload code somewhere
and post link here..
Anonymous
2010-09-03
anyone gotten this to work ?
davispuh
2010-09-04
me :D
you'll need distribute (it's
like setuptools)
then run:
python setup.py install
thats all ;)
PS. sometimes you need run twice...
Jason
2010-09-16
C:\Users\Jason\Downloads\MySQL-python-1.2.3-py3k\MySQL-
python-1.2.3-py3k>python setup.py install
Traceback (most recent call last):
File "setup.py", line 15, in
metadata, options = get_config()
File "C:\Users\Jason\Downloads\MySQL-python-1.2.3-py3k\MySQL-
python-1.2.3-py3k\setup_windows.py", line 7, in get_config
serverKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, options)
WindowsError: The system cannot find the file specified
I'll figure this out sooner or later. Regardless, thank you for your awesome
work, it's greatly appreciated. I didn't want to start a huge project in
Python2 when really, things should be moving towards 3
Jason
2010-09-16
It was because I didn't have MySQL installed on my local machine.
Anonymous
2010-09-30
PS C:\MySQL-python-1.2.3-py3k> python
Python 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> exit() PS C:\MySQL-python-1.2.3-py3k> mysql -h localhost -u root -p Enter password: ********* Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1692 Server version: 5.5.5-m3 MySQL Community Server (GPL) Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit Bye PS C:\MySQL-python-1.2.3-py3k> python setup.py install Traceback (most recent call last): File "setup.py", line 15, in <module> metadata, options = get_config() File "C:\MySQL-python-1.2.3-py3k\setup_windows.py", line 7, in get_config serverKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, options['registry_key']) WindowsError: [Error 2] The system cannot find the file specified PS C:\MySQL-python-1.2.3-py3k>
obviously i have mysql installed, get this error....
would be great if this worked...
Anonymous
2010-09-30
just tried it on another machine with a non-beta version of mysql, same
error...
this is win64 if that helps.
Anonymous
2010-10-01
You gotta edit site.cfg and set the registry key appropriately, depending on
what version of MySQL you have installed.
Anonymous
2010-10-03
I can get this working with mysql 5.1 with python 3.1.2 32-bit on windows xp
sp3 32-bit with visual studio c++ 2008 express.
I can not get this working with mysql 5.1 64-bit with python 3.1.2 64-bit on
windows 7 64-bit with visual studio c++ 2008 express.
has this been tested on windows 7, or on any windows 64-bit platform, any
luck? hints?
Anonymous
2010-10-03
A binary for windows 7 64-bit and python 3.1.2 64-bit would be amazingly
appreciated.
davispuh
2010-10-03
I wasn't any problem with win7 x64
you were lucky: MySQL-python-1.2.3-py3.1-win-
amd64
Windows 7, VS 2010, MySQL 5.1, Python 3.1.2
>setup.py install running install install_dir H:\Python31\Lib\site-packages\ running bdist_egg running egg_info writing MySQL_python.egg-info\PKG-INFO writing top-level names to MySQL_python.egg-info\top_level.txt writing dependency_links to MySQL_python.egg-info\dependency_links.txt reading manifest file 'MySQL_python.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no files found matching 'MANIFEST' warning: no files found matching 'ChangeLog' warning: no files found matching 'GPL' writing manifest file 'MySQL_python.egg-info\SOURCES.txt' installing library code to build\bdist.win-amd64\egg running install_lib running build_py creating build creating build\lib.win-amd64-3.1 copying _mysql_exceptions.py -> build\lib.win-amd64-3.1 creating build\lib.win-amd64-3.1\MySQLdb copying MySQLdb\__init__.py -> build\lib.win-amd64-3.1\MySQLdb copying MySQLdb\converters.py -> build\lib.win-amd64-3.1\MySQLdb copying MySQLdb\connections.py -> build\lib.win-amd64-3.1\MySQLdb copying MySQLdb\cursors.py -> build\lib.win-amd64-3.1\MySQLdb copying MySQLdb\release.py -> build\lib.win-amd64-3.1\MySQLdb copying MySQLdb\times.py -> build\lib.win-amd64-3.1\MySQLdb creating build\lib.win-amd64-3.1\MySQLdb\constants copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.1\MySQLdb\constants copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.1\MySQLdb\constants copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.1\MySQLdb\constants copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.1\MySQLdb\constants copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.1\MySQLdb\constants copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.1\MySQLdb\constants copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.1\MySQLdb\constants running build_ext building '_mysql' extension creating build\temp.win-amd64-3.1 creating build\temp.win-amd64-3.1\Release C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 "-IH:\MySQL\MySQL Server 5.1\include" -IH:\Python31\include -IH:\Python31\PC /Tc_mysql.c /Fobuild\temp.win-amd64-3.1\Release\_mysql.obj /Zl_mysql.c ...some warnings... C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO "/LIBPATH:H:\MySQL\MySQL Server 5.1\lib\opt" /LIBPATH:H:\Python31\libs /LIBPATH:H:\Python31\PCbuild\amd64 kernel32.lib advapi32.lib wsock32.lib mysqlclient.lib /EXPORT:PyInit__mysql build\temp.win-amd64-3.1\Release\_mysql.obj /OUT:build\lib.win-amd64-3.1\_mysql.pyd /IMPLIB:build\temp.win-amd64-3.1\Release\_mysql.lib /MANIFESTFILE:build\temp.win-amd64-3.1\Release\_mysql.pyd.manifest_mysql.obj warning LNK4197: export 'PyInit__mysql' specified multiple times; using first specification Creating library build\temp.win-amd64-3.1\Release\_mysql.lib and object build\temp.win-amd64-3.1\Release\_mysql.exp _mysql.obj : warning LNK4217: locally defined symbol strncat imported in function _mysql_row_to_dict _mysql.obj : warning LNK4217: locally defined symbol strncpy imported in function _mysql_row_to_dict _mysql.obj : warning LNK4217: locally defined symbol sprintf imported in function _mysql_ConnectionObject_repr C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\x64\mt.exe -nologo -manifest build\temp.win-amd64-3.1\Release\_mysql.pyd.manifest -outputresource:build\lib.win-amd64-3.1\_mysql.pyd;2 build\temp.win-amd64-3.1\Release\_mysql.pyd.manifest : general error c1010070: Failed to load and parse the manifest. System couldn't find specified file.error: command 'mt.exe' failed with exit status 31 >setup.py install running install install_dir H:\Python31\Lib\site-packages\ running bdist_egg running egg_info writing MySQL_python.egg-info\PKG-INFO writing top-level names to MySQL_python.egg-info\top_level.txt writing dependency_links to MySQL_python.egg-info\dependency_links.txt reading manifest file 'MySQL_python.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no files found matching 'MANIFEST' warning: no files found matching 'ChangeLog' warning: no files found matching 'GPL' writing manifest file 'MySQL_python.egg-info\SOURCES.txt' installing library code to build\bdist.win-amd64\egg running install_lib running build_py copying MySQLdb\release.py -> build\lib.win-amd64-3.1\MySQLdb running build_ext creating build\bdist.win-amd64 creating build\bdist.win-amd64\egg creating build\bdist.win-amd64\egg\MySQLdb copying build\lib.win-amd64-3.1\MySQLdb\connections.py -> build\bdist.win-amd64\egg\MySQLdb creating build\bdist.win-amd64\egg\MySQLdb\constants copying build\lib.win-amd64-3.1\MySQLdb\constants\CLIENT.py -> build\bdist.win-amd64\egg\MySQLdb\constants copying build\lib.win-amd64-3.1\MySQLdb\constants\CR.py -> build\bdist.win-amd64\egg\MySQLdb\constants copying build\lib.win-amd64-3.1\MySQLdb\constants\ER.py -> build\bdist.win-amd64\egg\MySQLdb\constants copying build\lib.win-amd64-3.1\MySQLdb\constants\FIELD_TYPE.py -> build\bdist.win-amd64\egg\MySQLdb\constants copying build\lib.win-amd64-3.1\MySQLdb\constants\FLAG.py -> build\bdist.win-amd64\egg\MySQLdb\constants copying build\lib.win-amd64-3.1\MySQLdb\constants\REFRESH.py -> build\bdist.win-amd64\egg\MySQLdb\constants copying build\lib.win-amd64-3.1\MySQLdb\constants\__init__.py -> build\bdist.win-amd64\egg\MySQLdb\constants copying build\lib.win-amd64-3.1\MySQLdb\converters.py -> build\bdist.win-amd64\egg\MySQLdb copying build\lib.win-amd64-3.1\MySQLdb\cursors.py -> build\bdist.win-amd64\egg\MySQLdb copying build\lib.win-amd64-3.1\MySQLdb\release.py -> build\bdist.win-amd64\egg\MySQLdb copying build\lib.win-amd64-3.1\MySQLdb\times.py -> build\bdist.win-amd64\egg\MySQLdb copying build\lib.win-amd64-3.1\MySQLdb\__init__.py -> build\bdist.win-amd64\egg\MySQLdb copying build\lib.win-amd64-3.1\_mysql.pyd -> build\bdist.win-amd64\egg copying build\lib.win-amd64-3.1\_mysql_exceptions.py -> build\bdist.win-amd64\egg byte-compiling build\bdist.win-amd64\egg\MySQLdb\connections.py to connections.pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\CLIENT.py to CLIENT.pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\CR.py to CR.pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\ER.py to ER.pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\FIELD_TYPE.py to FIELD_TYPE.pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\FLAG.py to FLAG.pycbyte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\REFRESH.py to REFRESH .pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\constants\__init__.py to __init__.pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\converters.py to converters.pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\cursors.py to cursors.pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\release.py to release.pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\times.py to times.pyc byte-compiling build\bdist.win-amd64\egg\MySQLdb\__init__.py to __init__.pyc byte-compiling build\bdist.win-amd64\egg\_mysql_exceptions.py to _mysql_exceptions.pyc creating stub loader for _mysql.pyd byte-compiling build\bdist.win-amd64\egg\_mysql.py to _mysql.pyc creating build\bdist.win-amd64\egg\EGG-INFO copying MySQL_python.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO copying MySQL_python.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO copying MySQL_python.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO copying MySQL_python.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt zip_safe flag not set; analyzing archive contents... creating dist creating 'dist\MySQL_python-1.2.3-py3.1-win-amd64.egg' and adding 'build\bdist.win-amd64\egg' to it removing 'build\bdist.win-amd64\egg' (and everything under it) Processing MySQL_python-1.2.3-py3.1-win-amd64.egg creating h:\python31\lib\site-packages\MySQL_python-1.2.3-py3.1-win-amd64.egg Extracting MySQL_python-1.2.3-py3.1-win-amd64.egg to h:\python31\lib\site-packages Adding MySQL-python 1.2.3 to easy-install.pth file Installed h:\python31\lib\site-packages\mysql_python-1.2.3-py3.1-win-amd64.egg Processing dependencies for MySQL-python==1.2.3 Finished processing dependencies for MySQL-python==1.2.3 >
Anonymous
2010-10-04
thanks a million!
Del Hyman-Jones
2010-10-15
I had to set the following for Vista x64 in the site.cfg file:
registry_key = SOFTWARE\Wow6432Node\MySQL AB\MySQL Server 5.1
This got me a bit further but now I've got a missing header file when running
setup.py install:
_mysql.c(34) : fatal error C1083: Cannot open include file: 'config-win.h': No
such file or directory
Where do I get this file? Any ideas?
randoms
2010-11-16
I am totally new to python, and since im using it in a academic manner I'm
lucky enough to be forced to use python3.
I managed to install the MySQL module, but when i try to include it in a file,
i get the following error:
pc-120-104:server eirik$ python3 server.py Traceback (most recent call last): File "server.py", line 8, in <module> import MySQLdb File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/MySQL_python-1.2.3-py3.1-macosx-10.3-fat.egg/MySQLdb/__init__.py", line 19, in <module> import _mysql ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/MySQL_python-1.2.3-py3.1-macosx-10.3-fat.egg/_mysql.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/MySQL_python-1.2.3-py3.1-macosx-10.3-fat.egg/_mysql.so: mach-o, but wrong architecture pc-120-104:server eirik$
I am using Mac Os X Snow Leopard. any ideas?
Anonymous
2010-11-17
look at site.cfg and change
registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0
on
registry_key = SOFTWARE\MySQL AB\MySQL Server 5.1
-- depends on your MySQL version
davispuh
2010-11-20
I've never used Mac, so I don't know, but looks like you have compiled it for
wrong architecture... or you haven't compiled it...
look at site.cfg and change registry_key = SOFTWARE\MySQL AB\MySQL Server
5.0 on registry_key = SOFTWARE\MySQL AB\MySQL Server 5.1 -- depends on your
MySQL version
I think Mac doesn't have registry, or does it?
conexion2000
2010-12-22
I used it with python 27. I used queries like curs.execute("select %s from
table", parameter), but now it doesn't work with 3.1. %s isn't converted.
davispuh
2010-12-24
yes, because in python 3 there are no %s format modifier, please read pyhton 3
manual ;)
now you have to do this way "select {!s} from table", param or "select {} from
table", param
davispuh
2010-12-24
sorry previous link was mistake...
read this: Format String
Syntax
Traker
2010-12-26
I`m having trouble installing this using:
Win 7 x64, MySQL 5.5, Python 3.1, VisualC++ 2008 Express with Windows SDK with
x64 libraries:
I have all the env variables for python, visual c++ but no luck...this is what
i get
-1.2.3-py3k>python setup.py install running install install_dir C:\Python31\Lib\site-packages\ running bdist_egg running egg_info writing MySQL_python.egg-info\PKG-INFO writing top-level names to MySQL_python.egg-info\top_level.txt writing dependency_links to MySQL_python.egg-info\dependency_links.txt reading manifest file 'MySQL_python.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no files found matching 'MANIFEST' warning: no files found matching 'ChangeLog' warning: no files found matching 'GPL' writing manifest file 'MySQL_python.egg-info\SOURCES.txt' installing library code to build\bdist.win-amd64\egg running install_lib running build_py copying MySQLdb\release.py -> build\lib.win-amd64-3.1\MySQLdb running build_ext building '_mysql' extension C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe /c /nolog o /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 "-IC:\Program Files\MySQL\MySQL Server 5.5\include" -IC:\Python31\include -IC:\ Python31\PC /Tc_mysql.c /Fobuild\temp.win-amd64-3.1\Release\_mysql.obj /Zl _mysql.c C:\Program Files\MySQL\MySQL Server 5.5\include\config-win.h(24) : warning C4005 : '_WIN32_WINNT' : macro redefinition C:\Program Files\Microsoft SDKs\Windows\v7.0\include\sdkddkver.h(197) : see previous definition of '_WIN32_WINNT' C:\Program Files\MySQL\MySQL Server 5.5\include\config-win.h(203) : warning C400 5: 'SIZEOF_OFF_T' : macro redefinition c:\python31\include\pyconfig.h(343) : see previous definition of 'SIZEOF _OFF_T' C:\Program Files\MySQL\MySQL Server 5.5\include\config-win.h(301) : warning C400 5: 'HAVE_STDDEF_H' : macro redefinition c:\python31\include\pyconfig.h(682) : see previous definition of 'HAVE_S TDDEF_H' _mysql.c(242) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', poss ible loss of data _mysql.c(267) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', poss ible loss of data _mysql.c(394) : warning C4244: 'initializing' : conversion from 'Py_ssize_t' to 'int', possible loss of data _mysql.c(1004) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', pos sible loss of data _mysql.c(1107) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', pos sible loss of data _mysql.c(1337) : warning C4267: '=' : conversion from 'size_t' to 'int', possibl e loss of data _mysql.c(1339) : warning C4267: '=' : conversion from 'size_t' to 'int', possibl e loss of data _mysql.c(1383) : warning C4267: '=' : conversion from 'size_t' to 'int', possibl e loss of data _mysql.c(1385) : warning C4267: '=' : conversion from 'size_t' to 'int', possibl e loss of data _mysql.c(2139) : warning C4244: 'function' : conversion from '__int64' to 'long' , possible loss of data C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\link.exe /DLL /n ologo /INCREMENTAL:NO "/LIBPATH:C:\Program Files\MySQL\MySQL Server 5.5\lib\opt" /LIBPATH:C:\Python31\libs /LIBPATH:C:\Python31\PCbuild\amd64 kernel32.lib advap i32.lib wsock32.lib mysqlclient.lib /EXPORT:PyInit__mysql build\temp.win-amd64-3 .1\Release\_mysql.obj /OUT:build\lib.win-amd64-3.1\_mysql.pyd /IMPLIB:build\temp .win-amd64-3.1\Release\_mysql.lib /MANIFESTFILE:build\temp.win-amd64-3.1\Release \_mysql.pyd.manifest LINK : fatal error LNK1181: cannot open input file 'mysqlclient.lib' error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64 \link.exe"' failed with exit status 1181
Traker
2010-12-26
ok, so i got it to work with MySQL 5.1
also if anyone is interested these instructions helped to remove some of the
errors i was getting:
http://www.fuyun.org/2009/12/install-mysql-for-python-on-
windows/
Traker
2010-12-27
I got it to work mate...it`s just a matter of having some patience
and...wisdom ;)
davispuh
2011-02-26
Here is updated version for MySQL 5.5 (I think this will NOT work for MySQL <
5.5) and Python 3.2 (works on Python 3.1 too) MySQL-python-1.2.3-py3k-
mysql5.5-updated.zip
Tested on Win7 x64 with MS Visual Studio 2010 + WinSDK 7.1; Python 3.2 and
MySQL 5.5
changed files: _mysql.c setup_windows.py site.cfg added: win_build.cmd
It's never been so easy to compile it for windows ;)
Enjoy
NOTE!
If you gen "error: Unable to find vcvarsall.bat"
then edit file "\Lib\distutils\msvc9compiler.py"
at line ~294 replace "VERSION = get_build_version()" with
"#VERSION = get_build_version()
VERSION = 10.0"
PS. this is for MS VS2010 to work...
if you encounter any problems you can try post here and i'll try to help if I
have time...
davispuh
2011-02-26
sorry little typo in previous post.. download it here: MySQL-python-1.2.3
-py3k-mysql5.5-updated
PS. It's very bad that posts can be edited :(