[python] Python 3.4.0 with MySQL database

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?

This question is related to python mysql python-3.x mysql-python python-3.4

The answer is


Install pip:

apt-get install pip

For acess MySQL from Python, install:

pip3 install mysqlclient

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


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


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


mysqlclient is a fork of MySQLdb and can serve as a drop-in replacement with Python 3.4 support. If you have trouble building it on Windows, you can download it from Christoph Gohlke's Unofficial Windows Binaries for Python Extension Packages


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.


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...


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!


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


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()

Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to mysql

Implement specialization in ER diagram How to post query parameters with Axios? PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' is not supported How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Connection Java-MySql : Public Key Retrieval is not allowed How to grant all privileges to root user in MySQL 8.0 MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

Examples related to python-3.x

Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation Replace specific text with a redacted version using Python Upgrade to python 3.8 using conda "Permission Denied" trying to run Python on Windows 10 Python: 'ModuleNotFoundError' when trying to import module from imported package What is the meaning of "Failed building wheel for X" in pip install? How to downgrade python from 3.7 to 3.6 I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? Iterating over arrays in Python 3 How to upgrade Python version to 3.7?

Examples related to mysql-python

mysql-python install error: Cannot open include file 'config-win.h' Python 3.4.0 with MySQL database ImportError: No module named MySQLdb Install mysql-python (Windows) IndexError: tuple index out of range ----- Python cursor.fetchall() vs list(cursor) in Python How to insert pandas dataframe via mysqldb into database? Visibility of global variables in imported modules Replacing Pandas or Numpy Nan with a None to use with MysqlDB mysql_config not found when installing mysqldb python interface

Examples related to python-3.4

No module named 'openpyxl' - Python 3.4 - Ubuntu How to install pip in CentOS 7? Python3 project remove __pycache__ folders and .pyc files Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing OSError: [WinError 193] %1 is not a valid Win32 application enum - getting value of enum on string conversion Pandas - Plotting a stacked Bar Chart Python 3.4.0 with MySQL database How could I use requests in asyncio?