ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

½T»{MySQL Using Connector/Python³s½u¦¨¥\

½T»{MySQL Using Connector/Python³s½u¦¨¥\

¦³Ãö Connecting to MySQL 5.6 Using Connector/Python¥i¥H°Ñ¦ÒMySQL Connector/Python Developer Guide¡A¦bChapter 5 Connector/Python Coding Examples¦³¡G
5.1 Connecting to MySQL Using Connector/Python
5.2 Creating Tables Using Connector/Python
5.3 Inserting Data Using Connector/Python
5.4 Querying Data Using Connector/Python
´N5.1 Connecting to MySQL Using Connector/Python³¡¥÷¡A»¡©ú¤å¥óÁö¦³´£¨Ñ½d¨Ò¡A¦ý§ÚÁÙ¬O¨Ì·Ó¦Û¤vªº»Ý­n§@¨Ç­×§ï¡A©Î¥i¨Ñ«áÄòªº¤H°Ñ¦Ò¡A³s½u´ú¸Õ½d¨Òµ{¦¡¦p¤U¡G
  1. import mysql.connector
  2. from mysql.connector import errorcode

  3. try:
  4.   cnx = mysql.connector.connect(user='root', password='http://forum.twbts.com',
  5.                               host='127.0.0.1',
  6.                               database='world')
  7. except mysql.connector.Error as err:
  8.   if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
  9.     print("Something is wrong with your user name or password")
  10.   elif err.errno == errorcode.ER_BAD_DB_ERROR:
  11.     print("Database does not exists")
  12.   else:
  13.     print(err)
  14.     exit(1)
  15. else:   
  16.   print("Congratulation! Your Connector/Python Installation is Verified.")  
  17.   cnx.close()
½Æ»s¥N½X
«Ü©êºp¡A§Ú¬O¤p¾Ç¥Í¡A¤£¯à¤U¸üÀɮסA¬O­Ó¤p§¾«Ä¡I

        ÀR«ä¦Û¦b : ¦n¨Æ­n´£±o°_¡A¬O«D­n©ñ±o¤U¡A¦¨´N§O¤H§Y¬O¦¨´N¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD