MySQL Connector/Python 開發人員指南

摘要

本手冊說明如何安裝和設定 MySQL Connector/Python,這是一個用於與 MySQL 伺服器通訊的獨立 Python 驅動程式,以及如何使用它來開發資料庫應用程式。

建議最新的 MySQL Connector/Python 版本與 MySQL Server 8.0 及更高版本搭配使用。

如需詳細了解每個 Connector/Python 版本中的變更,請參閱MySQL Connector/Python 版本注意事項

如需法律資訊,請參閱法律聲明

如需使用 MySQL 的協助,請造訪MySQL 論壇,您可以在那裡與其他 MySQL 使用者討論您的問題。

授權資訊。 本產品可能包含在授權下使用的第三方軟體。如果您使用的是 MySQL Connector/Python 的商業版本,請參閱MySQL Connector/Python 9.0 商業授權資訊使用者手冊,以取得授權資訊,包括與本商業版本中可能包含的第三方軟體相關的授權資訊。如果您使用的是 MySQL Connector/Python 的社群版本,請參閱MySQL Connector/Python 9.0 社群授權資訊使用者手冊,以取得授權資訊,包括與本社群版本中可能包含的第三方軟體相關的授權資訊。

文件產生於:2024-07-18 (修訂版:79066)

目錄

前言與法律聲明
1 MySQL Connector/Python 簡介
2 Python 開發人員指南
3 Connector/Python 版本
4 Connector/Python 安裝
4.1 取得 Connector/Python
4.2 從二進位發行版本安裝 Connector/Python
4.3 從原始碼發行版本安裝 Connector/Python
4.4 驗證您的 Connector/Python 安裝
5 Connector/Python 程式碼範例
5.1 使用 Connector/Python 連線至 MySQL
5.2 使用 Connector/Python 建立資料表
5.3 使用 Connector/Python 插入資料
5.4 使用 Connector/Python 查詢資料
6 Connector/Python 教學
6.1 教學:使用緩衝游標提高員工薪資
7 Connector/Python 連線建立
7.1 Connector/Python 連線引數
7.2 Connector/Python 選項檔案支援
8 Connector/Python C 擴充功能
8.1 使用 Connector/Python C 擴充功能進行應用程式開發
8.2 _mysql_connector C 擴充功能模組
9 Connector/Python 其他主題
9.1 Connector/Python 記錄
9.2 遙測支援
9.3 非同步連線
9.4 Connector/Python 連線集區
9.5 Connector/Python Django 後端
10 Connector/Python API 參考
10.1 mysql.connector 模組
10.1.1 mysql.connector.connect() 方法
10.1.2 mysql.connector.apilevel 屬性
10.1.3 mysql.connector.paramstyle 屬性
10.1.4 mysql.connector.threadsafety 屬性
10.1.5 mysql.connector.__version__ 屬性
10.1.6 mysql.connector.__version_info__ 屬性
10.2 connection.MySQLConnection 類別
10.2.1 connection.MySQLConnection() 建構函式
10.2.2 MySQLConnection.close() 方法
10.2.3 MySQLConnection.commit() 方法
10.2.4 MySQLConnection.config() 方法
10.2.5 MySQLConnection.connect() 方法
10.2.6 MySQLConnection.cursor() 方法
10.2.7 MySQLConnection.cmd_change_user() 方法
10.2.8 MySQLConnection.cmd_debug() 方法
10.2.9 MySQLConnection.cmd_init_db() 方法
10.2.10 MySQLConnection.cmd_ping() 方法
10.2.11 MySQLConnection.cmd_process_info() 方法
10.2.12 MySQLConnection.cmd_process_kill() 方法
10.2.13 MySQLConnection.cmd_query() 方法
10.2.14 MySQLConnection.cmd_query_iter() 方法
10.2.15 MySQLConnection.cmd_quit() 方法
10.2.16 MySQLConnection.cmd_refresh() 方法
10.2.17 MySQLConnection.cmd_reset_connection() 方法
10.2.18 MySQLConnection.cmd_shutdown() 方法
10.2.19 MySQLConnection.cmd_statistics() 方法
10.2.20 MySQLConnection.disconnect() 方法
10.2.21 MySQLConnection.get_row() 方法
10.2.22 MySQLConnection.get_rows() 方法
10.2.23 MySQLConnection.get_server_info() 方法
10.2.24 MySQLConnection.get_server_version() 方法
10.2.25 MySQLConnection.is_connected() 方法
10.2.26 MySQLConnection.isset_client_flag() 方法
10.2.27 MySQLConnection.ping() 方法
10.2.28 MySQLConnection.reconnect() 方法
10.2.29 MySQLConnection.reset_session() 方法
10.2.30 MySQLConnection.rollback() 方法
10.2.31 MySQLConnection.set_charset_collation() 方法
10.2.32 MySQLConnection.set_client_flags() 方法
10.2.33 MySQLConnection.shutdown() 方法
10.2.34 MySQLConnection.start_transaction() 方法
10.2.35 MySQLConnection.autocommit 屬性
10.2.36 MySQLConnection.unread_results 屬性
10.2.37 MySQLConnection.can_consume_results 屬性
10.2.38 MySQLConnection.charset 屬性
10.2.39 MySQLConnection.collation 屬性
10.2.40 MySQLConnection.connection_id 屬性
10.2.41 MySQLConnection.database 屬性
10.2.42 MySQLConnection.get_warnings 屬性
10.2.43 MySQLConnection.in_transaction 屬性
10.2.44 MySQLConnection.raise_on_warnings 屬性
10.2.45 MySQLConnection.server_host 屬性
10.2.46 MySQLConnection.server_port 屬性
10.2.47 MySQLConnection.sql_mode 屬性
10.2.48 MySQLConnection.time_zone 屬性
10.2.49 MySQLConnection.unix_socket 屬性
10.2.50 MySQLConnection.user 屬性
10.3 pooling.MySQLConnectionPool 類別
10.3.1 pooling.MySQLConnectionPool 建構函式
10.3.2 MySQLConnectionPool.add_connection() 方法
10.3.3 MySQLConnectionPool.get_connection() 方法
10.3.4 MySQLConnectionPool.set_config() 方法
10.3.5 MySQLConnectionPool.pool_name 屬性
10.4 pooling.PooledMySQLConnection 類別
10.4.1 pooling.PooledMySQLConnection 建構函式
10.4.2 PooledMySQLConnection.close() 方法
10.4.3 PooledMySQLConnection.config() 方法
10.4.4 PooledMySQLConnection.pool_name 屬性
10.5 cursor.MySQLCursor 類別
10.5.1 cursor.MySQLCursor 建構函式
10.5.2 MySQLCursor.add_attribute() 方法
10.5.3 MySQLCursor.clear_attributes() 方法
10.5.4 MySQLCursor.get_attributes() 方法
10.5.5 MySQLCursor.callproc() 方法
10.5.6 MySQLCursor.close() 方法
10.5.7 MySQLCursor.execute() 方法
10.5.8 MySQLCursor.executemany() 方法
10.5.9 MySQLCursor.fetchall() 方法
10.5.10 MySQLCursor.fetchmany() 方法
10.5.11 MySQLCursor.fetchone() 方法
10.5.12 MySQLCursor.fetchwarnings() 方法
10.5.13 MySQLCursor.stored_results() 方法
10.5.14 MySQLCursor.column_names 屬性
10.5.15 MySQLCursor.description 屬性
10.5.16 MySQLCursor.lastrowid 屬性
10.5.17 MySQLCursor.rowcount 屬性
10.5.18 MySQLCursor.statement 屬性
10.5.19 MySQLCursor.with_rows 屬性
10.6 cursor.MySQLCursor 的子類別
10.6.1 cursor.MySQLCursorBuffered 類別
10.6.2 cursor.MySQLCursorRaw 類別
10.6.3 cursor.MySQLCursorBufferedRaw 類別
10.6.4 cursor.MySQLCursorDict 類別
10.6.5 cursor.MySQLCursorBufferedDict 類別
10.6.6 cursor.MySQLCursorNamedTuple 類別
10.6.7 cursor.MySQLCursorBufferedNamedTuple 類別
10.6.8 cursor.MySQLCursorPrepared 類別
10.7 constants.ClientFlag 類別
10.8 constants.FieldType 類別
10.9 constants.SQLMode 類別
10.10 constants.CharacterSet 類別
10.11 constants.RefreshOption 類別
10.12 錯誤與例外
10.12.1 errorcode 模組
10.12.2 errors.Error 例外
10.12.3 errors.DataError 例外
10.12.4 errors.DatabaseError 例外
10.12.5 errors.IntegrityError 例外
10.12.6 errors.InterfaceError 例外
10.12.7 errors.InternalError 例外
10.12.8 errors.NotSupportedError 例外
10.12.9 errors.OperationalError 例外
10.12.10 errors.PoolError 例外
10.12.11 errors.ProgrammingError 例外
10.12.12 errors.Warning 例外
10.12.13 errors.custom_error_exception() 函數
11 Connector/Python C 擴充功能 API 參考
11.1 _mysql_connector 模組
11.2 _mysql_connector.MySQL() 類別
11.3 _mysql_connector.MySQL.affected_rows() 方法
11.4 _mysql_connector.MySQL.autocommit() 方法
11.5 _mysql_connector.MySQL.buffered() 方法
11.6 _mysql_connector.MySQL.change_user() 方法
11.7 _mysql_connector.MySQL.character_set_name() 方法
11.8 _mysql_connector.MySQL.close() 方法
11.9 _mysql_connector.MySQL.commit() 方法
11.10 _mysql_connector.MySQL.connect() 方法
11.11 _mysql_connector.MySQL.connected() 方法
11.12 _mysql_connector.MySQL.consume_result() 方法
11.13 _mysql_connector.MySQL.convert_to_mysql() 方法
11.14 _mysql_connector.MySQL.escape_string() 方法
11.15 _mysql_connector.MySQL.fetch_fields() 方法
11.16 _mysql_connector.MySQL.fetch_row() 方法
11.17 _mysql_connector.MySQL.field_count() 方法
11.18 _mysql_connector.MySQL.free_result() 方法
11.19 _mysql_connector.MySQL.get_character_set_info() 方法
11.20 _mysql_connector.MySQL.get_client_info() 方法
11.21 _mysql_connector.MySQL.get_client_version() 方法
11.22 _mysql_connector.MySQL.get_host_info() 方法
11.23 _mysql_connector.MySQL.get_proto_info() 方法
11.24 _mysql_connector.MySQL.get_server_info() 方法
11.25 _mysql_connector.MySQL.get_server_version() 方法
11.26 _mysql_connector.MySQL.get_ssl_cipher() 方法
11.27 _mysql_connector.MySQL.hex_string() 方法
11.28 _mysql_connector.MySQL.insert_id() 方法
11.29 _mysql_connector.MySQL.more_results() 方法
11.30 _mysql_connector.MySQL.next_result() 方法
11.31 _mysql_connector.MySQL.num_fields() 方法
11.32 _mysql_connector.MySQL.num_rows() 方法
11.33 _mysql_connector.MySQL.ping() 方法
11.34 _mysql_connector.MySQL.query() 方法
11.35 _mysql_connector.MySQL.raw() 方法
11.36 _mysql_connector.MySQL.refresh() 方法
11.37 _mysql_connector.MySQL.reset_connection() 方法
11.38 _mysql_connector.MySQL.rollback() 方法
11.39 _mysql_connector.MySQL.select_db() 方法
11.40 _mysql_connector.MySQL.set_character_set() 方法
11.41 _mysql_connector.MySQL.shutdown() 方法
11.42 _mysql_connector.MySQL.stat() 方法
11.43 _mysql_connector.MySQL.thread_id() 方法
11.44 _mysql_connector.MySQL.use_unicode() 方法
11.45 _mysql_connector.MySQL.warning_count() 方法
11.46 _mysql_connector.MySQL.have_result_set 屬性
索引