確認MySQL Using Connector/Python連線成功
- 帖子
- 48
- 主題
- 6
- 精華
- 0
- 積分
- 60
- 點名
- 0
- 作業系統
- XP
- 軟體版本
- Office 2003
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2012-8-13
- 最後登錄
- 2023-2-7
|
確認MySQL Using Connector/Python連線成功
有關 Connecting to MySQL 5.6 Using Connector/Python可以參考MySQL Connector/Python Developer Guide,在Chapter 5 Connector/Python Coding Examples有:
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
就5.1 Connecting to MySQL Using Connector/Python部份,說明文件雖有提供範例,但我還是依照自己的需要作些修改,或可供後續的人參考,連線測試範例程式如下:- import mysql.connector
- from mysql.connector import errorcode
- try:
- cnx = mysql.connector.connect(user='root', password='http://forum.twbts.com',
- host='127.0.0.1',
- database='world')
- except mysql.connector.Error as err:
- if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
- print("Something is wrong with your user name or password")
- elif err.errno == errorcode.ER_BAD_DB_ERROR:
- print("Database does not exists")
- else:
- print(err)
- exit(1)
- else:
- print("Congratulation! Your Connector/Python Installation is Verified.")
- cnx.close()
複製代碼 |
|
很抱歉,我是小學生,不能下載檔案,是個小屁孩!
|
|
|
|
|