MySQL 8 导入报错:'ascii' codec can't decode byte 0xd2 in position 26: ordinal not in range(128)

更新日期: 2019-01-06 阅读次数: 15085 分类: MySQL

系统环境

  • Windows 10
  • MySQL Server 8.0.12
  • MySQL Workbench 8.0.12

现象

从另一台开发机上导出的数据库备份,无法在本机导入,MySQL Workbench 报错

21:37:49 Restoring D:\geo2.sql
Error executing task: 'ascii' codec can't decode byte 0xd2 in position 26: ordinal not in range(128)
Error executing task [Error 32] : 'c:\\users\\\xd2\xbc\xd2\xbb\\appdata\\local\\temp\\tmpjx4rq_.cnf'
21:37:50 Import of D:\geo2.sql has finished

导出的机器 (WSL 下的 MySQL),Workbench 导出时也是报类似的错误,无奈使用 MySQL 命令行导出的 SQL 文件。

解决方法

还是命令行靠谱。

> cd /mnt/d/
> mysql --host=127.0.0.1 --user=root --password
mysql > use geo2;
mysql > source geo2.sql;

在 WSL 下就可以成功导入。

WSL 下使用 MySQL Client 连接 Win10 上安装的 MySQL

> mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

需要指定 HOST

> mysql --host=127.0.0.1 --user=root --password
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.12 MySQL Community Server - GPL

rank 在 mysql 8 中变成了保留关键字

在新环境中,有一行 SQL 一直报错

order by rank desc

看了半天猜测 rank 是关键词,果然

order by `rank` desc

改成这样就好了。

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式