user670186
user670186

Reputation: 2840

install python MySQLdb to python3 not python

i have Ubuntu and installed python3 since my script is written in it. Since I use MYSQL with MySQLdb, I installed

apt-get install python-mysqldb

however this installed MySQLdb to Python (which is 2.6 on Ubuntu) and not to Python3.

  1. How can I install MySQLdb for Python3
  2. Should I use it at all or switch to PyMSQL

Sorry, I have just started working with Python today...

Upvotes: 10

Views: 20344

Answers (7)

Aly Radwan
Aly Radwan

Reputation: 209

1- You can use this command sudo apt-get install python3-mysqldb

It worked for me.

2- also you can install pip install PyMySQL.

Then add lines to __init__.py file

# __init__.py file

import pymysql
pymysql.install_as_MySQLdb()

Upvotes: 9

kgf3JfUtW
kgf3JfUtW

Reputation: 14908

How to install MySQLdb for Python2

sudo apt-get install python-mysqldb

How to install MySQLdb for Python3

sudo apt-get install python3-mysqldb

Upvotes: 2

Vishal
Vishal

Reputation: 1559

If you are planning to switch from MySQLDB then I recommend you to use MySQL connector Python

Why ?

  • it work with both Python 2 and 3

  • Because it is official Oracle driver for MySQL for working with Python.

  • It is purely written in Python

  • You can also use C extension to connect to MySQL.

  • MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. This means you don't have to compile anything or MySQL doesn't even have to be installed on the machine.

  • Also, it has great support for connection pooling

Upvotes: 1

Ludo Schmidt
Ludo Schmidt

Reputation: 1403

This was a success for me on linux (UBUNTU) and anaconda:

sudo apt-get install libmysqlclient-dev ( it get mysql_config )

then

pip3 install git+git://github.com/davispuh/MySQL-for-Python-3

that's it...

More info on https://github.com/davispuh/MySQL-for-Python-3/wiki/Install-on-Linux

Upvotes: 1

Thamayron Alves
Thamayron Alves

Reputation: 33

you can use this:

https://github.com/davispuh/MySQL-for-Python-3/wiki/Install-on-Linux

It worked for me.

Upvotes: 2

unutbu
unutbu

Reputation: 879103

MySQLdb is not yet Python3 compatible, but oursql, a Python-MySQL driver, is.

Upvotes: 4

shadyabhi
shadyabhi

Reputation: 17234

As far as I know, it's not ported to python3 yet.

Upvotes: 2

Related Questions