【mysql】解决source命令导入 带utf-8字符的.sql 产生乱码的问题

原先是用mysqldump备份的,为了图简便本想在phpmyadmin 中导入,发现速度太慢。转到mysql -uxxx -pxxx下用source /tmp/data.sql导入,提示成功后,打开phpmyadmin,发现数据都变成了乱码。后用如下方法解决:

mysql> SHOW VARIABLES LIKE ‘character_set_%’;
+————————–+—————————-+
| Variable_name | Value |
+————————–+—————————-+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+————————–+—————————-+
7 rows in set (0.00 sec)

mysql> set NAMES ‘utf8′;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_database=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_server=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like ‘character%’;
+————————–+——————————–+
| Variable_name | Value |
+————————–+——————————–+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+————————–+——————————–+
8 rows in set (0.00 sec)

mysql>source /tmp/data.sql

再打开phpmyadmin,问题解决。

服务器上:
进入mysql数据库:
mysql -u root -p
输入数据库密码:
退出:
exit

备份检验数据库
mysqldump -u root -p (--dafault-character-set=utf8) db > db.sql
还原
mysqldump -u root -p (--dafault-character-set=utf8) db < db.sql

SET NAMES utf8;

source ***.sql;

你可能感兴趣的:(【mysql】解决source命令导入 带utf-8字符的.sql 产生乱码的问题)