SHARE
TWEET

DB

a guest Oct 23rd, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top