From 2ffc8d3b8982e0c3eb370995252d29bc11313704 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 3 Sep 2018 22:44:58 +0200 Subject: [PATCH] create a script to read mariadb data --- mariadb_read_data.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/mariadb_read_data.py b/mariadb_read_data.py index 478a5ac..6eb64b9 100644 --- a/mariadb_read_data.py +++ b/mariadb_read_data.py @@ -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() +