[个人原创]mysql source 导入utf8编码显示正常方法

jackxiang 2009-12-25 21:17 | |
在mysql中涉及到编码是最让人头疼的。
编写update.txt (注意:utf8的编码要存为utf8的txt格式,当然你也可以命名后缀改为:update.sql etc)
source的sql包含中文(位置在/root/update.txt):
update Tbl_User set FAddr="四川内江东兴区平安路148号E栋8号" where FQQ="348813422";


mysql> use DB_****_2nd;
Database changed
mysql> source /root/update.txt
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0


然后,发现php程序读出来发现是乱码。
查看mysql编码:
mysql> show variables like '%char%';

mysql> show variables like '%char%';
+--------------------------+----------------------------------------------------------------------+
| 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     | latin1                                                               |
| character_set_system     | utf8                                                                 |
| character_sets_dir       | /usr/local/mysql-max-5.0.27-linux-i686-glibc23/share/mysql/charsets/ |
+--------------------------+----------------------------------------------------------------------+
8 rows in set (0.00 sec)


原来是:
| character_set_server     | latin1                                                               |
不是utf-8:
于是:需要,set names 'utf8';


mysql> set names "utf8";
Query OK, 0 rows affected (0.00 sec)

mysql> source /root/update.txt
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql>


在php中显示中文正常,哈哈哈!

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/2385/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2009-12-25 21:30
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]