I'm a new Python developer but have successfully worked with python and mysql on a Windows machine. I am struggling to figure it out on my new Ubuntu platform (v 16.04). Here's what I've done .
My machine has both python 2.7 and 3.5 installed in usr/bin
I installed this mysql library
sudo apt-get install python-mysqldb
I got no errors.
I get into python3 and do
import MySQLdb
It gives an error no module named MySQLdb
I get into python (2.7)
The import works and I can do some queries.
So I don't really get what's going on with these multiple versions of python. I don't want to work in python 2.7. Did I install a mysqldb that only works in python 2.7?
Assuming the library isn't the correct one, I went to the Oracle Mysql site and downloaded the correct package for my Ubuntu distro and then tried to install it following their instructions:
sudo dpkg -i mysql-connector-python_2.1.6-1ubuntu16.10_all.deb
This won't install because :
dpkg: regarding mysql-connector-python_2.1.6-1ubuntu16.10_all.deb containing mysql-connector-python: mysql-connector-python conflicts with python-mysql.connector python-mysql.connector (version 2.0.4-1) is present and installed.
So now I'm in trouble the first package only works in python 2.7 but it's presence seems to now interfere with installing the mysql-connector-python.
I tried running
sudo apt-get remove python-mysqldb
which completes without errors. But my next attempt at sudo dpkg -i mysql-connector-python_2.1.6-1ubuntu16.10_all.deb
still fails with the same message.
So I'm confused about a number of things:
Installing things when both pythons are on my machine and knowing which one (or both) they will affect.
Is the mysql-connector from Oracle the preferred one to use for Python 3.5 development? I saw some mention that it has bugs and that people use this python-mysqldb one instead but then I've seen some mention that it isn't supported for python 3.
So at this point I don't know which to use, how to get rid of what I've installed that is wrong, how to install the correct one. And then ultimately I'd like to see a couple lines of python that show me how to import the right package and test a connection.