User avatar
micksulley
Posts: 147
Joined: Sat Mar 03, 2012 11:48 am
Location: Melton Mowbray, England

Connect to MariaDB from Python

Mon Jan 29, 2018 2:56 pm

Up to date Raspbian. I have installed MariaDB following this link
https://howtoraspberrypi.com/mariadb-ra ... pberry-pi/
and I am trying to connect to it from within Python following information here
https://mariadb.com/resources/blog/how- ... ms-mariadb
but it fails at the import statement

Code: Select all

>>> import mysql.connector as mariadb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named mysql.connector
>>> 
Have I missed something here? Do I need to install something else

User avatar
Jednorozec
Posts: 809
Joined: Sun Nov 24, 2013 2:17 pm
Location: Deposit, NY

Re: Connect to MariaDB from Python

Mon Jan 29, 2018 8:24 pm

MariaDB provides Python support through the MySQL Python package, which does not come installed with the default Python installation on most distros.
Did you install it?
The most important leg of a three legged stool is the one that's missing.
It's called thinking. Why don't you try it sometime?

User avatar
micksulley
Posts: 147
Joined: Sat Mar 03, 2012 11:48 am
Location: Melton Mowbray, England

Re: Connect to MariaDB from Python - Fixed

Mon Jan 29, 2018 9:06 pm

Yes that was it, all working now.
Many Thanks
Mick

MadeMess
Posts: 1
Joined: Fri Aug 24, 2018 3:02 pm

Re: Connect to MariaDB from Python

Fri Aug 24, 2018 3:23 pm

For anyone else that comes through here - I couldn't get it working until I lucked into the right download:

Code: Select all

sudo apt-get libmariadbclient-dev
This enabled:

Code: Select all

pip install mysql-connector 
As per https://github.com/sanpingz/mysql-connector provided example, I was able to connect.

This was for python3.7 running in virtualenv.

rivandemo
Posts: 5
Joined: Fri May 12, 2017 12:06 pm

Re: Connect to MariaDB from Python

Sat Dec 08, 2018 4:03 pm

I think "install" is missing after "sudo apt-get" in "sudo apt-get libmariadbclient-dev"

Return to “Python”