【MYSQL】MYSQL报错解决方法: Warning: (3719, "'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8M B4 in a future release."

  

  用python3.6.5创建mysql库时出现如下报错,虽然报错,但是数据库可以插入成功。

D:\python3\lib\site-packages\pymysql\cursors.py:170: Warning: (3719, "'utf8' is
currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 
in a future release. Please consider using UTF8MB4 in order to be unambiguous.")
  result = self._query(query)

  

 解决方法

  •   python版本:3.6.5
  •   mysql版本: 8.0.12

  

  1. 首先查看下mysql字符集

mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | gbk                |
| character_set_connection | gbk                |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | gbk                |
| character_set_server     | utf8mb4            |
| character_set_system     | utf8               |
| collation_connection     | gbk_chinese_ci     |
| collation_database       | utf8mb4_0900_ai_ci |
| collation_server         | utf8mb4_0900_ai_ci |
+--------------------------+--------------------+
10 rows in set, 1 warning (0.04 sec)

  

  2. 根据上述查询结果,修改sql语句

修改前 = 'CREATE DATABASE IF NOT EXISTS database_name DEFAULT CHARSET utf8 COLLATE utf8_general_ci;'
修改后 = 'CREATE DATABASE IF NOT EXISTS database_name DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci;'

  DEFAULT CHARSET utf8 COLLATE utf8_general_ci 是之前老版sql的写法。

  

  代码执行创建成功~(๑•̀ㅂ•́)و✧

  

  相关知识补充

  UTF8MB4与UTF8MB3的区别介绍:https://dev.mysql.com/doc/refman/5.6/en/charset-unicode-utf8mb4.html

 

posted @ 2018-12-12 17:27  LiliP  阅读(21241)  评论(3编辑  收藏  举报