2015-12-05 64 views
2

我有一個python-flask播客應用程序,我在年初寫了。數據庫配置爲使用utf8mb4字符集(完整的UTF-8)(並具有默認的排序規則utf8mb4_bin)連接到mysql的問題5.7.9數據庫與utf8mb4

我正在使用python-mysql-1.2.5 mysql 5.7.9在mac優勝美地,但我的python應用程序嘗試掛起連接到數據庫。通過自制軟件安裝。它安裝到/usr/local/Cellar/mysql/5.7.9/

大量調試i後可以看到,掛起是在一行中 /用戶/ XXX /回購/ mypodweb/env的/ lib中存在的/python2.7/site-packages/MySQLdb/connections.py

在功能

import types, _mysql 
... 
def set_character_set(self, charset): 
     """Set the connection character set to charset. The character 
     set can only be changed in MySQL-4.1 and newer. If you try 
     to change the character set from the current value in an 
     older version, NotSupportedError will be raised.""" 
     if charset == "utf8mb4": 
      py_charset = "utf8" 
     else: 
      py_charset = charset 
     if self.character_set_name() != charset: 
      try: 
       super(Connection, self).set_character_set(charset) #<<<-- here 
      except AttributeError: 
       if self._server_version < (4, 1): 
        raise NotSupportedError("server is too old to set charset") 
       self.query('SET NAMES %s' % charset) 
       self.store_result() 
     self.string_decoder.charset = py_charset 
     self.unicode_literal.charset = py_charset 

所以這個引用_mysql.set_character_set(字符集),它只是沒有輸出掛起......

因此,它看起來_mysql.so是本機庫綁定?我猜如此...

我注意到的一件事是,有一個不同版本的mysql庫 - mysql 5.7.9只有/usr/local/Cellar/mysql/5.7.9/lib/libmysqlclient。 20.dylib 但_mysql.so引用libmysqlclient.18.dylib

該庫似乎工作,雖然我可以看到掛起後在mysql中的睡眠連接。所以建立了連接,然後庫試圖設置字符集。 (第二排)。

mysql> SHOW FULL PROCESSLIST; 
+----+------+-----------------+--------------+---------+------+----------+-----------------------+ 
| Id | User | Host   | db   | Command | Time | State | Info     | 
+----+------+-----------------+--------------+---------+------+----------+-----------------------+ 
| 3 | root | localhost  | NULL   | Query | 0 | starting | SHOW FULL PROCESSLIST | 
| 5 | root | localhost:52486 | mypodweb_dev | Sleep | 4 |   | NULL     | 
+----+------+-----------------+--------------+---------+------+----------+-----------------------+ 
2 rows in set (0.00 sec) 

所以錯誤發生時,我開始嘗試在我使用蒸餾器來管理遷移遷移我的數據庫。我也嘗試使用QueuePool(而不是NullPool)來裝載默認的alembic env.py文件 - 唯一的區別是我在mysql中獲得了2個到mypodweb_dev的睡眠連接。

mysql> SHOW FULL PROCESSLIST; 
+----+------+-----------------+--------------+---------+------+----------+-----------------------+ 
| Id | User | Host   | db   | Command | Time | State | Info     | 
+----+------+-----------------+--------------+---------+------+----------+-----------------------+ 
| 4 | root | localhost:53359 | mypodweb_dev | Sleep | 961 |   | NULL     | 
| 5 | root | localhost:53856 | mypodweb_dev | Sleep | 19 |   | NULL     | 
| 6 | root | localhost  | NULL   | Query | 0 | starting | SHOW FULL PROCESSLIST | 
+----+------+-----------------+--------------+---------+------+----------+-----------------------+ 

我找不到任何東西,當我谷歌這個問題。尋找解決方法或解決方法,只會讓我去,因爲它只是我的本地開發環境,我被困在莫的起始門。

回答

0

python-mysql-1.2.5只支持MySQL 5.5以上

+0

在http://bugs.mysql.com上提交一個bug。 –