A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://stackoverflow.com/questions/23376103/python-3-4-0-with-mysql-database below:

Python 3.4.0 with MySQL database

Asked 11 years, 3 months ago

Viewed 151k times

I have installed Python version 3.4.0 and I would like to do a project with MySQL database. I downloaded and tried installing MySQLdb, but it wasn't successful for this version of Python.

Any suggestions how could I fix this problem and install it properly?

codeforester

43.6k2121 gold badges121121 silver badges157157 bronze badges

asked Apr 29, 2014 at 22:01

Srdjan RisticSrdjan Ristic

3,53355 gold badges2020 silver badges2323 bronze badges

0

MySQLdb does not support Python 3 but it is not the only MySQL driver for Python.

mysqlclient is essentially just a fork of MySQLdb with Python 3 support merged in (and a few other improvements).

PyMySQL is a pure python MySQL driver, which means it is slower, but it does not require a compiled C component or MySQL libraries and header files to be installed on client machines. It has Python 3 support.

Another option is simply to use another database system like PostgreSQL.

answered Apr 29, 2014 at 22:08

Andrew GorcesterAndrew Gorcester

20k88 gold badges6262 silver badges7474 bronze badges

10

Use mysql-connector-python. I prefer to install it with pip from PyPI:

pip install --allow-external mysql-connector-python mysql-connector-python

Have a look at its documentation and examples.

If you are going to use pooling make sure your database has enough connections available as the default settings may not be enough.

answered Jul 23, 2014 at 0:38

lxxlxx

1,3542121 silver badges3131 bronze badges

7

Install pip:

apt-get install pip

For acess MySQL from Python, install:

pip3 install mysqlclient

answered Nov 29, 2015 at 3:14

1

There is a Ubuntu solution available either through the Ubuntu Software Center or through the Synaptic Package Manager. This will connect Python version 3.4.0 to MySQL. Download "python3-mysql.connector" version 1.1.6-1.

Note that the connection syntax does not use "MySQLdb". Instead read: Connecting to MySQL Using Connector/Python

answered Jun 1, 2015 at 20:45

Steve R.Steve R.

23022 silver badges1313 bronze badges

sudo apt-get install python3-dev
sudo apt-get install libmysqlclient-dev
sudo apt-get install zlib1g-dev
sudo pip3 install mysqlclient

that worked for me!

answered Dec 13, 2017 at 22:45

0

I solved it this way: download the zipped package from here and follow this set of instructions:

unzip  /path/to/downloads/folder/mysql-connector-python-VER.zip  

In case u got a .gz u can use ->

tar xzf mysql-connector-python-VER.tar.gz 

And then:

cd mysql-connector-python-VER  # move into the directory

sudo python3 setup.py install # NOTICE I USED PYTHON3 INSTEAD OF PYTHON

You can read about it here

answered Jan 1, 2016 at 18:20

SanDSanD

48177 silver badges1111 bronze badges

It seems that at the moment Ubuntu 15.10 has a but with python3 and pip3.

As elaborated in this article.

The problem makes pip3 install to python3.5 while python3 is actually running python3.4 :(

Until a proper solution will be available via the updates you can do one of the following:

run

python3 -m pip install pymysql

instead of

pip3 install pymysql

(or any other package)

Now

import pymysql

should work in python3 and in idle3.

Alternatively, if you explicitly need 3.5 you can use explicit python3.5 instead of python3. but idle3 will still point to 3.4...

answered Dec 2, 2015 at 21:41

QT-1QT-1

1,0161616 silver badges2424 bronze badges

1

Alternatively, you can use mysqlclient or oursql. For oursql, use the oursql py3k series as my link points to.

answered Jul 28, 2015 at 12:45

Frozen FlameFrozen Flame

3,26344 gold badges2626 silver badges3838 bronze badges

Maybe you can use a work around and try something like:

import datetime
#import mysql
import MySQLdb
conn = MySQLdb.connect(host = '127.0.0.1',user = 'someUser', passwd = 'foobar',db = 'foobardb')
cursor = conn.cursor()
HPierce

7,42977 gold badges3636 silver badges4949 bronze badges

answered Oct 1, 2016 at 12:20

2

for fedora and python3 use: dnf install mysql-connector-python3

answered Mar 9, 2018 at 0:59

Protected question

. To answer this question, you need to have at least 10 reputation on this site (not counting the

association bonus

). The reputation requirement helps protect this question from spam and non-answer activity.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4