How to connect Mariadb with python3?

4

Friends, is there any way to connect Python 3 with MariaDB? Also, could you indicate any material in English or Portuguese?

Thank you in advance!

    
asked by anonymous 03.05.2015 / 20:01

2 answers

1

To connect to MariaDB using the MySQL Python module in your program, you have to import it first, just like any other module. For clarity and ease of use, import the connector class only under the import mysql.connector as mariadb name. I will use the class under the name mariadb in the following examples. Then, establish a database connection with code like mariadb_connection = mariadb.connect (user = 'python_user', password = 'some_pass', database = 'employees') where you assign actual values for user, password and database. Finally, to begin interacting with the database and running queries, you need to instantiate the cursor object with the cursor = mariadb_connection.cursor () tag. So far, your initial code should look something like this:

! / Usr / bin / python

Import mysql.connector as mariadb

Mariadb_connection = mariadb.connect (user = 'python_user', password = 'some_pass', database = 'employees') Cursor = mariadb_connection.cursor ()

Here you have the complete, easy-to-understand material: link

    
18.03.2017 / 15:21
2

As MariaDB is the same MySQL core, you can use the same MySQL module to access the DB.

Access this link and see

    
23.07.2015 / 00:27