How to connect Mariadb with python3?

Asked

Viewed 2,021 times

5

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

Thank you in advance!

  • 1

    Mariadb is just an implementation of Mysql (afaik), so any documentation you find about connecting Python with Mysql should be valid. In Google for sure there are several.

  • 2

    https://mariadb.com/blog/how-connect-python-programs-mariadb

  • 1

    take a look here... http://stackoverflow.com/questions/13846050/python-3-mysql-connector they explain the situation...

3 answers

2


To connect to Mariadb using the Mysql Python module in your program, you have to import it first, as well as any other module. For clarity and ease of use, import the connector class only under the name import mysql.Connector as mariadb. I will use the class under the name mariadb in the following examples. Then establish a database connection with code such as mariadb_connection = mariadb.connect(user='python_user', password='some_pass', database='Employees') , where you assign real values to user, password and database. Finally, to start interacting with the database and executing queries, you need to instantiate the cursor object with the code cursor = mariadb_connection.cursor(). So far, your initial code should be similar to this:

! / Usr / bin / python

Import mysql.Connect as mariadb

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

Here is the complete material, easy to understand: https://mariadb.com/resources/blog/how-connect-python-programs-mariadb

1

-2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.