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!
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!
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:
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
Since Mariadb is the same core as Mysql, you can use the same Mysql module to access DB.
-2
https://cadernodelaboratorio.com.br/pymysql-integrando-python-com-o-mariadb/
import pymysql.cursors
con = pymysql.connect(host='', user='', password='', database='', cursorclass=pymysql.cursors.DictCursor)
with con.cursor() as c:
sql = "SELECT *FROM *"
c.execute(sql)
res = c.fetchone()
print(res)
con.close()
Browser other questions tagged python-3.x mariadb
You are not signed in. Login or sign up in order to post.
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.
– Vinícius Gobbo A. de Oliveira
https://mariadb.com/blog/how-connect-python-programs-mariadb
– bruno
take a look here... http://stackoverflow.com/questions/13846050/python-3-mysql-connector they explain the situation...
– Kelvin Kredens