20 lines
610 B
Python
20 lines
610 B
Python
|
#!/usr/bin/python
|
||
|
import mysql.connector as mariadb
|
||
|
|
||
|
mariadb_connection = mariadb.connect(user='vagrant',
|
||
|
database='testdb')
|
||
|
cursor = mariadb_connection.cursor()
|
||
|
cursor.execute("""create table if not exists test (
|
||
|
a bigint auto_increment primary key,
|
||
|
first_name varchar(128),
|
||
|
last_name varchar(128))""")
|
||
|
cursor.execute("""INSERT INTO test (first_name,last_name) VALUES (%s,%s)""",
|
||
|
("first_name", "last_name"))
|
||
|
|
||
|
mariadb_connection.commit()
|
||
|
|
||
|
cursor.execute("select * from test")
|
||
|
data = cursor.fetchall()
|
||
|
for row in data:
|
||
|
print(row)
|