Advertisement
Guest User

DB

a guest
Oct 23rd, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import mysql.connector
  2. from mysql.connector import Error
  3.  
  4. try:
  5.     connection = mysql.connector.connect()
  6.  
  7.     if connection.is_connected():
  8.         db_Info = connection.get_server_info()
  9.         print("Connected to MySQL Server version ", db_Info)
  10.         cursor = connection.cursor()
  11.         cursor.execute("select database();")
  12.         record = cursor.fetchone()
  13.         print("Your connected to database: ", record)
  14.  
  15. except Error as e:
  16.     print("Error while connecting to MySQL", e)
  17. finally:
  18.     if (connection.is_connected()):
  19.         cursor.close()
  20.         connection.close()
  21.         print("MySQL connection is closed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement