@@ -8,7 +8,7 @@ MySQLdb User's Guide
8
8
Introduction
9
9
------------
10
10
11
- MySQLdb is a thread-compatible interface to the popular MySQL
11
+ MySQLdb is a interface to the popular MySQL
12
12
database server that provides the Python database API.
13
13
14
14
Installation
@@ -28,7 +28,7 @@ for this module is intentionally weak because you probably should use
28
28
the higher-level MySQLdb module. If you really need it, use the
29
29
standard MySQL docs and transliterate as necessary.
30
30
31
- .. _`MySQL documentation` : http ://dev.mysql.com/doc/
31
+ .. _`MySQL documentation` : https ://dev.mysql.com/doc/
32
32
33
33
34
34
MySQL C API translation
@@ -55,48 +55,48 @@ MySQL C API function mapping
55
55
C API ``_mysql ``
56
56
=================================== ==================================
57
57
``mysql_affected_rows() `` ``conn.affected_rows() ``
58
- ``mysql_autocommit() `` ``conn.autocommit() ``
59
- ``mysql_character_set_name() `` ``conn.character_set_name() ``
60
- ``mysql_close() `` ``conn.close() ``
61
- ``mysql_commit() `` ``conn.commit() ``
62
- ``mysql_connect() `` ``_mysql.connect() ``
63
- ``mysql_data_seek() `` ``result.data_seek() ``
64
- ``mysql_debug() `` ``_mysql.debug() ``
65
- ``mysql_dump_debug_info `` ``conn.dump_debug_info() ``
66
- ``mysql_escape_string() `` ``_mysql.escape_string() ``
67
- ``mysql_fetch_row() `` ``result.fetch_row() ``
58
+ ``mysql_autocommit() `` ``conn.autocommit() ``
59
+ ``mysql_character_set_name() `` ``conn.character_set_name() ``
60
+ ``mysql_close() `` ``conn.close() ``
61
+ ``mysql_commit() `` ``conn.commit() ``
62
+ ``mysql_connect() `` ``_mysql.connect() ``
63
+ ``mysql_data_seek() `` ``result.data_seek() ``
64
+ ``mysql_debug() `` ``_mysql.debug() ``
65
+ ``mysql_dump_debug_info `` ``conn.dump_debug_info() ``
66
+ ``mysql_escape_string() `` ``_mysql.escape_string() ``
67
+ ``mysql_fetch_row() `` ``result.fetch_row() ``
68
68
``mysql_get_character_set_info() `` ``conn.get_character_set_info() ``
69
- ``mysql_get_client_info() `` ``_mysql.get_client_info() ``
70
- ``mysql_get_host_info() `` ``conn.get_host_info() ``
71
- ``mysql_get_proto_info() `` ``conn.get_proto_info() ``
72
- ``mysql_get_server_info() `` ``conn.get_server_info() ``
73
- ``mysql_info() `` ``conn.info() ``
74
- ``mysql_insert_id() `` ``conn.insert_id() ``
75
- ``mysql_num_fields() `` ``result.num_fields() ``
76
- ``mysql_num_rows() `` ``result.num_rows() ``
77
- ``mysql_options() `` various options to ``_mysql.connect() ``
78
- ``mysql_ping() `` ``conn.ping() ``
79
- ``mysql_query() `` ``conn.query() ``
80
- ``mysql_real_connect() `` ``_mysql.connect() ``
81
- ``mysql_real_query() `` ``conn.query() ``
82
- ``mysql_real_escape_string() `` ``conn.escape_string() ``
83
- ``mysql_rollback() `` ``conn.rollback() ``
84
- ``mysql_row_seek() `` ``result.row_seek() ``
85
- ``mysql_row_tell() `` ``result.row_tell() ``
86
- ``mysql_select_db() `` ``conn.select_db() ``
87
- ``mysql_set_character_set() `` ``conn.set_character_set() ``
69
+ ``mysql_get_client_info() `` ``_mysql.get_client_info() ``
70
+ ``mysql_get_host_info() `` ``conn.get_host_info() ``
71
+ ``mysql_get_proto_info() `` ``conn.get_proto_info() ``
72
+ ``mysql_get_server_info() `` ``conn.get_server_info() ``
73
+ ``mysql_info() `` ``conn.info() ``
74
+ ``mysql_insert_id() `` ``conn.insert_id() ``
75
+ ``mysql_num_fields() `` ``result.num_fields() ``
76
+ ``mysql_num_rows() `` ``result.num_rows() ``
77
+ ``mysql_options() `` various options to ``_mysql.connect() ``
78
+ ``mysql_ping() `` ``conn.ping() ``
79
+ ``mysql_query() `` ``conn.query() ``
80
+ ``mysql_real_connect() `` ``_mysql.connect() ``
81
+ ``mysql_real_query() `` ``conn.query() ``
82
+ ``mysql_real_escape_string() `` ``conn.escape_string() ``
83
+ ``mysql_rollback() `` ``conn.rollback() ``
84
+ ``mysql_row_seek() `` ``result.row_seek() ``
85
+ ``mysql_row_tell() `` ``result.row_tell() ``
86
+ ``mysql_select_db() `` ``conn.select_db() ``
87
+ ``mysql_set_character_set() `` ``conn.set_character_set() ``
88
88
``mysql_ssl_set() `` ``ssl `` option to ``_mysql.connect() ``
89
- ``mysql_stat() `` ``conn.stat() ``
90
- ``mysql_store_result() `` ``conn.store_result() ``
91
- ``mysql_thread_id() `` ``conn.thread_id() ``
92
- ``mysql_thread_safe_client() `` ``conn.thread_safe_client() ``
93
- ``mysql_use_result() `` ``conn.use_result() ``
94
- ``mysql_warning_count() `` ``conn.warning_count() ``
95
- ``CLIENT_* `` ``MySQLdb.constants.CLIENT.* ``
96
- ``CR_* `` ``MySQLdb.constants.CR.* ``
97
- ``ER_* `` ``MySQLdb.constants.ER.* ``
98
- ``FIELD_TYPE_* `` ``MySQLdb.constants.FIELD_TYPE.* ``
99
- ``FLAG_* `` ``MySQLdb.constants.FLAG.* ``
89
+ ``mysql_stat() `` ``conn.stat() ``
90
+ ``mysql_store_result() `` ``conn.store_result() ``
91
+ ``mysql_thread_id() `` ``conn.thread_id() ``
92
+ ``mysql_thread_safe_client() `` ``conn.thread_safe_client() ``
93
+ ``mysql_use_result() `` ``conn.use_result() ``
94
+ ``mysql_warning_count() `` ``conn.warning_count() ``
95
+ ``CLIENT_* `` ``MySQLdb.constants.CLIENT.* ``
96
+ ``CR_* `` ``MySQLdb.constants.CR.* ``
97
+ ``ER_* `` ``MySQLdb.constants.ER.* ``
98
+ ``FIELD_TYPE_* `` ``MySQLdb.constants.FIELD_TYPE.* ``
99
+ ``FLAG_* `` ``MySQLdb.constants.FLAG.* ``
100
100
=================================== ==================================
101
101
102
102
@@ -126,7 +126,7 @@ We haven't even begun to touch upon all the parameters ``connect()``
126
126
can take. For this reason, I prefer to use keyword parameters::
127
127
128
128
db=_mysql.connect(host="localhost",user="joebob",
129
- passwd="moonpie",db="thangs")
129
+ passwd="moonpie",db="thangs")
130
130
131
131
This does exactly what the last example did, but is arguably easier to
132
132
read. But since the default host is "localhost", and if your login
@@ -260,19 +260,19 @@ Functions and attributes
260
260
Only a few top-level functions and attributes are defined within
261
261
MySQLdb.
262
262
263
- connect(parameters...)
264
- Constructor for creating a connection to the
265
- database. Returns a Connection Object. Parameters are the
266
- same as for the MySQL C API. In addition, there are a few
267
- additional keywords that correspond to what you would pass
268
- ``mysql_options() `` before connecting. Note that some
269
- parameters must be specified as keyword arguments! The
270
- default value for each parameter is NULL or zero, as
271
- appropriate. Consult the MySQL documentation for more
272
- details. The important parameters are:
263
+ connect(parameters...)
264
+ Constructor for creating a connection to the
265
+ database. Returns a Connection Object. Parameters are the
266
+ same as for the MySQL C API. In addition, there are a few
267
+ additional keywords that correspond to what you would pass
268
+ ``mysql_options() `` before connecting. Note that some
269
+ parameters must be specified as keyword arguments! The
270
+ default value for each parameter is NULL or zero, as
271
+ appropriate. Consult the MySQL documentation for more
272
+ details. The important parameters are:
273
273
274
274
host
275
- name of host to connect to. Default: use the local host
275
+ name of host to connect to. Default: use the local host
276
276
via a UNIX socket (where applicable)
277
277
278
278
user
@@ -284,11 +284,11 @@ connect(parameters...)
284
284
db
285
285
database to use. Default: no default database.
286
286
287
- port
288
- TCP port of MySQL server. Default: standard port (3306).
287
+ port
288
+ TCP port of MySQL server. Default: standard port (3306).
289
289
290
290
unix_socket
291
- location of UNIX socket. Default: use default location or
291
+ location of UNIX socket. Default: use default location or
292
292
TCP for remote hosts.
293
293
294
294
conv
@@ -331,45 +331,45 @@ connect(parameters...)
331
331
connecting (MySQL-4.1 and later), you'll need to put the
332
332
correct character set name in connection.charset.
333
333
334
- If False, text-like columns are returned as normal strings,
335
- but you can always write Unicode strings.
334
+ If False, text-like columns are returned as normal strings,
335
+ but you can always write Unicode strings.
336
336
337
- *This must be a keyword parameter. *
337
+ *This must be a keyword parameter. *
338
338
339
- charset
340
- If present, the connection character set will be changed
341
- to this character set, if they are not equal. Support for
342
- changing the character set requires MySQL-4.1 and later
343
- server; if the server is too old, UnsupportedError will be
344
- raised. This option implies use_unicode=True, but you can
345
- override this with use_unicode=False, though you probably
346
- shouldn't.
339
+ charset
340
+ If present, the connection character set will be changed
341
+ to this character set, if they are not equal. Support for
342
+ changing the character set requires MySQL-4.1 and later
343
+ server; if the server is too old, UnsupportedError will be
344
+ raised. This option implies use_unicode=True, but you can
345
+ override this with use_unicode=False, though you probably
346
+ shouldn't.
347
347
348
- If not present, the default character set is used.
348
+ If not present, the default character set is used.
349
349
350
- *This must be a keyword parameter. *
350
+ *This must be a keyword parameter. *
351
351
352
- sql_mode
353
- If present, the session SQL mode will be set to the given
354
- string. For more information on sql_mode, see the MySQL
355
- documentation. Only available for 4.1 and newer servers.
352
+ sql_mode
353
+ If present, the session SQL mode will be set to the given
354
+ string. For more information on sql_mode, see the MySQL
355
+ documentation. Only available for 4.1 and newer servers.
356
356
357
- If not present, the session SQL mode will be unchanged.
357
+ If not present, the session SQL mode will be unchanged.
358
358
359
- *This must be a keyword parameter. *
359
+ *This must be a keyword parameter. *
360
360
361
- ssl
362
- This parameter takes a dictionary or mapping, where the
363
- keys are parameter names used by the mysql_ssl_set _ MySQL
364
- C API call. If this is set, it initiates an SSL connection
365
- to the server; if there is no SSL support in the client,
366
- an exception is raised. *This must be a keyword
367
- parameter. *
361
+ ssl
362
+ This parameter takes a dictionary or mapping, where the
363
+ keys are parameter names used by the mysql_ssl_set _ MySQL
364
+ C API call. If this is set, it initiates an SSL connection
365
+ to the server; if there is no SSL support in the client,
366
+ an exception is raised. *This must be a keyword
367
+ parameter. *
368
368
369
369
.. _mysql_ssl_set : http://dev.mysql.com/doc/refman/en/mysql-ssl-set.html
370
370
371
371
372
- apilevel
372
+ apilevel
373
373
String constant stating the supported DB API level. '2.0'
374
374
375
375
threadsafety
@@ -437,11 +437,11 @@ conv
437
437
value), returning a Python value
438
438
439
439
* a sequence of 2-tuples, where the first value is a combination
440
- of flags from ``MySQLdb.constants.FLAG ``, and the second value
441
- is a function as above. The sequence is tested until the flags
442
- on the field match those of the first value. If both values
443
- are None, then the default conversion is done. Presently this
444
- is only used to distinguish TEXT and BLOB columns.
440
+ of flags from ``MySQLdb.constants.FLAG ``, and the second value
441
+ is a function as above. The sequence is tested until the flags
442
+ on the field match those of the first value. If both values
443
+ are None, then the default conversion is done. Presently this
444
+ is only used to distinguish TEXT and BLOB columns.
445
445
446
446
If the key is a Python type or class, then the value is a
447
447
callable Python object (usually a function) taking two arguments
@@ -522,7 +522,7 @@ close()
522
522
523
523
info()
524
524
Returns some information about the last query. Normally
525
- you don't need to check this. If there are any MySQL
525
+ you don't need to check this. If there are any MySQL
526
526
warnings, it will cause a Warning to be issued through
527
527
the Python warning module. By default, Warning causes a
528
528
message to appear on the console. However, it is possible
@@ -542,7 +542,7 @@ nextset()
542
542
sets, it returns None; otherwise it returns a true value.
543
543
544
544
Note that MySQL doesn't support multiple result sets until 4.1.
545
-
545
+
546
546
547
547
Some examples
548
548
.............
@@ -598,13 +598,13 @@ The only other method you are very likely to use is when you have to
598
598
do a multi-row insert::
599
599
600
600
c.executemany(
601
- """INSERT INTO breakfast (name, spam, eggs, sausage, price)
602
- VALUES (%s, %s, %s, %s, %s)""",
603
- [
604
- ("Spam and Sausage Lover's Plate", 5, 1, 8, 7.95 ),
605
- ("Not So Much Spam Plate", 3, 2, 0, 3.95 ),
606
- ("Don't Wany ANY SPAM! Plate", 0, 4, 3, 5.95 )
607
- ] )
601
+ """INSERT INTO breakfast (name, spam, eggs, sausage, price)
602
+ VALUES (%s, %s, %s, %s, %s)""",
603
+ [
604
+ ("Spam and Sausage Lover's Plate", 5, 1, 8, 7.95 ),
605
+ ("Not So Much Spam Plate", 3, 2, 0, 3.95 ),
606
+ ("Don't Wany ANY SPAM! Plate", 0, 4, 3, 5.95 )
607
+ ] )
608
608
609
609
Here we are inserting three rows of five values. Notice that there is
610
610
a mix of types (strings, ints, floats) though we still only use
0 commit comments