Page 1 of 1

Connect to MariaDB from Python

Posted: Mon Jan 29, 2018 2:56 pm
by micksulley
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

Re: Connect to MariaDB from Python

Posted: Mon Jan 29, 2018 8:24 pm
by Jednorozec
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?

Re: Connect to MariaDB from Python - Fixed

Posted: Mon Jan 29, 2018 9:06 pm
by micksulley
Yes that was it, all working now.
Many Thanks
Mick

Re: Connect to MariaDB from Python

Posted: Fri Aug 24, 2018 3:23 pm
by MadeMess
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.

Re: Connect to MariaDB from Python

Posted: Sat Dec 08, 2018 4:03 pm
by rivandemo
I think "install" is missing after "sudo apt-get" in "sudo apt-get libmariadbclient-dev"