Reputation: 2840
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.
Sorry, I have just started working with Python today...
Upvotes: 10
Views: 20344
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
.
__init__.py
file# __init__.py file
import pymysql
pymysql.install_as_MySQLdb()
Upvotes: 9
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
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
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
Reputation: 33
you can use this:
https://github.com/davispuh/MySQL-for-Python-3/wiki/Install-on-Linux
It worked for me.
Upvotes: 2