13
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLdb.connectの引数全解説

Last updated at Posted at 2019-09-01

MySQLdbの基本的な使い方はMySQLdbでレコードを保存できない対処法(autocommitを使う)にて簡単に説明しているので,必要に応じてご覧下さい.

詳細
https://github.com/PyMySQL/mysqlclient-python/blob/master/MySQLdb/connections.py

パラメタ名                                           型            説明  
host str 接続するホスト名
user str 接続するためのMySQLのユーザー名
password str MySQLのパスワード
passwd str passwordへのエイリアス.後方互換性のために存在
database str 使用するデータベース名
db str databaseへのエイリアス.後方互換性のために存在
port int 接続するためのTCP/IPポート
unix_socket str 用いるunix_socketの場所
conv dict MySQLdb.converters関数のための辞書型引数.割愛
connect_timeout int 接続切れまでの時間(秒)
compress bool セットするとcompress(圧縮)する
named_pipe str セットすると名前付きパイプを使う(Windowsのみ)
init_command str 接続が開始されたときに走らせるコマンド
read_default_file str 設定するとこのファイルからデフォルトのクライアントの値が読まれる
read_default_group str デフォルトファイルから使うグループのconfiguration group
cursorclass type cursorを作るためのオブジェクトのクラス.(keywordのみ)
use_unicode bool Trueにすると,テキストlikeなカラムがconnectionの文字コードを使ったunicodeオブジェクトとして返ってくる.Falseなら,テキストlikeなカラムはバイト列として返ってくる.unicodeオブジェクトは常にこの設定に関わらずconnectionの文字コードとしてエンコードされる.デフォルトはPython2でFalse,Python3でTrueなので,デフォルトでPythonの'str'が常に手に入る.
charset str 設定すると,connectionの文字コードが変更される.Python2では,このオプションによってuse_unicodeオプションがFalseからTrueに変更される.
sql_mode str 設定すると,セッションのSQLモードが変更される.詳細はMySQLのドキュメントへ.
client_flag int 使うclient_flagの設定,client_flgについては詳細はMySQLのドキュメントへ.取れる引数はconstants/CLIENTS.pyでも見れる.
ssl dict SSL接続のパラメータを含む辞書ないしmapping.mysql_ssl_set()も参照.設定され,クライアントがSSLをサポートしていない場合,NotSupportedErrorが発生する.
local_infile bool LOAD LOCAL INFILEを有効にする.0ならば無効.
autocommit bool False(デフォルト)なら,自動コミットは無効.Trueなら有効.Noneなら自動コミットは設定されず,サーバーのデフォルトが使用される.
binary_prefix bool Trueに設定すると,_binaryという接尾語が(Binaryなどの)生のバイトのクエリの引数に使われる.これはデフォルトで無効.

charsetではutf8utf8mb4を使います.utf8mb4は4バイト文字の利用.autocommitTrueにすると,commit()をしなくてよくなります.

13
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?