mysql导出数据中文乱码问题

解决mysql导入导出数据乱码问题方法:

1、进入mysql,通过如下命令查看数据库编码方式:

mysql>  show variables like 'character_set_%';
+--------------------------+----------------------------------------+
| Variable_name            | Value                                  |
+--------------------------+----------------------------------------+
| character_set_client     | latin1                                 |
| character_set_connection | latin1                                 |
| character_set_database   | utf8                                   |
| character_set_filesystem | binary                                 |
| character_set_results    | latin1                                 |
| character_set_server     | latin1                                 |
| character_set_system     | utf8                                   |
| character_sets_dir       | /opt/mysql_root/base/share/charsets/ |

2、客户端导出数据命令加上设置编码语句:
根据上面显示数据库编码为utf8,因此加上编码参数为:--default-character-set=utf8

执行如下命令,将数据库为database1中的tableName中的数据导出到testexport.txt文件

mysql  --default-character-set=utf8 -uusername -ppasswd -hhost -Pport -Ddatabase1 -e " select * from tableName" > testexport.txt

你可能感兴趣的:(mysql,中文乱码,导数据)