LoginSignup
2
2

More than 3 years have passed since last update.

python3でMySQLのutf8mb4データベースへ接続する

Last updated at Posted at 2017-09-05

はじめに

 pythonからPyMySQL3ドライバを利用し、utf8mb4設定済みのデータベースにアクセスしました。すると、KeyError:45エラーが発生したので、代わりにMySQL公式が提供しているmysql-connector-python-rfドライバを利用したのですが、その際に軽いトラブルがあったので備忘も兼ねて記録しておきます。

環境

バージョン
OS macOS 10.12.6
python 3.6.1
pip 9.0.1
mysql-connector-python-rf 2.2.2
PyMySQL3(参考) 0.5

手順

 はじめに、ドライバをインストールする為、以下のコマンドを実行しました。

pip install mysql-connector-python-rf

ところが、

Command "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/j2/8h3wfb391t1_58crtwyc1xx00000gp/T/pip-build-6oqq9ezx/mysql-connector-python-rf/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/j2/8h3wfb391t1_58crtwyc1xx00000gp/T/pip-hwj0p9pe-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/j2/8h3wfb391t1_58crtwyc1xx00000gp/T/pip-build-6oqq9ezx/mysql-connector-python-rf/

というエラーが発生し、インストールできませんでした。そこで、いろいろ調べた結果、

pip install --egg mysql-connector-python-rf

--eggオプションを付加することでインストールに成功しました。こちらのドライバでは、問題なくutf8mb4データベースを操作することができています。

最後に

 インストールの際、 DEPRECATION: --egg has been deprecated and will be removed in the future. と警告が表示されたので、そのうち使えなくなるかもしれません。

2
2
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
2
2