From 87f79d843ec3df0727c0e8a68557930c507f3619 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Sat, 26 Sep 2020 02:02:56 -0500 Subject: mysql connect to db from python --- sql1.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sql1.py diff --git a/sql1.py b/sql1.py new file mode 100644 index 0000000..0f3f778 --- /dev/null +++ b/sql1.py @@ -0,0 +1,16 @@ +# pip install mysql-connector-python + +import mysql.connector + +mydb = mysql.connector.connect( + host="localhost", + user="root", + password="foobar", + database="employees" +) + +mycursor = mydb.cursor() +mycursor.execute("SHOW TABLES") +myresult = mycursor.fetchall() +for x in myresult: + print(x) \ No newline at end of file -- cgit v1.2.3