How to use python 3.5.1 with a MySQL database

2020-02-08 04:48发布

I have been trying to use MySQL in a Python project I've been working on. I downloaded the connector: mysql-connector-python-2.1.3-py3.4-winx64 here.

I already had Python 3.5.1 installed. When I tried to install the connector, it didn't work because it required python 2.7 instead. I have searched on many sites, even on StackOverflow I couldn't find a solution.

Thanks for any help.

7条回答
叼着烟拽天下
2楼-- · 2020-02-08 05:30

Try this link: MySQL - Downloads - Connector - Python

From Select Platform, select the platform independent an download MySQLconnector.

After extracting the file go to its directory where setup.py is located.

WINDOWS: press shift + right_click and open command windows and type:

python setup.py install`
查看更多
神经病院院长
3楼-- · 2020-02-08 05:31

I was facing mysql database connection problem with Windows, Python 3.5.2 and Django. But finally I resolved it by installing "mysqlclient‑1.3.9‑cp35‑cp35m‑win32.whl" from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

Download the whl file, then enter into same directory in command prompt and run the below command.

pip install mysqlclient-1.3.9-cp35-cp35m-win32.whl

Note: Python 3.5.2 does not have official support for MySQL yet, so its just un-official binary to over come this problem for now.

Hope that will help you !!!

查看更多
叛逆
4楼-- · 2020-02-08 05:38

Use the mysqlclient library. Install with: pip install mysqlclient

It is a fork of MySQLdb ( which was formerly installed via pip install mysql-python) that supports Python 3.*

This library talks to the MySQL client's C-interface, and is faster than the pure-python pymysql libray.

*Note: you will need the mysql-developer tools installed. An easy way to do this on a Mac is to run brew install mysql to delegate this task to homebrew. If you are on linux, you can install these via the instructions at the mysqlclient github page.

查看更多
手持菜刀,她持情操
5楼-- · 2020-02-08 05:41

I am using Python 3.5.2 on window 8 pro 64-bit and the following procedure is worked for me.

  1. Download driver (PyMySQL-0.7.9.tar.gz (md5)) from here

  2. Extract and copy the folder pymysql into the python Lib folder e.g (C:\Users\MyUsername\AppData\Local\Programs\Python\Python35-32\Lib)

  3. Copy and run the following example.py
#!/usr/bin/env python

import pymysql

conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='', db='sandbox')

cur = conn.cursor()
cur.execute("SELECT * FROM users")

print(cur.description)
print()

for row in cur:
    print(row)

cur.close()
conn.close()

I hope it will work for you as well. Happy coding :)

查看更多
Ridiculous、
6楼-- · 2020-02-08 05:42

In Windows, I used:

pip3 install pymysql
查看更多
Deceive 欺骗
7楼-- · 2020-02-08 05:46

Visit this web site and you will find a mysqld package that works fine with Python 3 on Windows : http://www.lfd.uci.edu/~gohlke/pythonlibs/

Otherwise you can use pymysql which might be slower but works fine with Python 3.

查看更多
登录 后发表回答