create a script to read mariadb data
This commit is contained in:
parent
12e855b77a
commit
2ffc8d3b89
|
@ -1,19 +1,26 @@
|
|||
#!/usr/bin/python
|
||||
import mysql.connector as mariadb
|
||||
import time
|
||||
|
||||
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()
|
||||
allowed_query = ("select username, hobby from user;")
|
||||
|
||||
cursor.execute("select * from test")
|
||||
print()
|
||||
print()
|
||||
print()
|
||||
print()
|
||||
print()
|
||||
start_time = time.time()
|
||||
cursor.execute(allowed_query)
|
||||
data = cursor.fetchall()
|
||||
for row in data:
|
||||
print(row)
|
||||
print("--- %s seconds ---" % (time.time() - start_time))
|
||||
print(len(data))
|
||||
print()
|
||||
print()
|
||||
print()
|
||||
print()
|
||||
print()
|
||||
|
||||
|
|
Loading…
Reference in New Issue