修改 windows: mysql-root/my.ini (mysql-4.1.14-win32.zip)
linux: /etc/my.cnf
将其中的default-character-set都改成gbk
也就是如下两个SECTION
[client]
。。。。
default-character-set=gbk
。。。。
[mysqld]
。。。。
default-character-set=gbk
。。。。
Linux上:
mysql> show variables like "%set%";
+--------------------------+----------------------------------------------------
----------------------+
| Variable_name | Value
|
+--------------------------+----------------------------------------------------
----------------------+
| character_set_client | gbk
|
| character_set_connection | gbk
|
| character_set_database | gbk
|
| character_set_results | gbk
|
| character_set_server | gbk
|
| character_set_system | utf8
|
| character_sets_dir | /usr/local/mysql-standard-4.1.12-pc-linux-gnu-i686/
share/mysql/charsets/ |
+--------------------------+----------------------------------------------------
----------------------+
7 rows in set (0.00 sec)
此时可以查看中文的字段,应该一切正常显示。如果不正常显示说明数据库中存放的不是正确编码。
Windows上:
mysql> show variables like "%set%";
+--------------------------+--------------------------+
| Variable_name | Value |
+--------------------------+--------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | gbk |
| character_set_results | latin1 |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | D:\MySql\share\charsets/ |
+--------------------------+--------------------------+
7 rows in set (0.00 sec)
不知道为什么在windows上my.ini中
[client]
。。。。
default-character-set=gbk
没有起作用。
Windows上登录mysql,更改会话的编码为gbk
mysql> set names "gbk";
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like "%set%";
+--------------------------+--------------------------+
| Variable_name | Value |
+--------------------------+--------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | gbk |
| character_set_results | gbk |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | D:\MySql\share\charsets/ |
+--------------------------+--------------------------+
7 rows in set (0.00 sec)
此时可以查看中文的字段,应该一切正常显示。如果不正常显示说明数据库中存放的不是正确编码。
完全备份MySql
Linux上:
mysqldump --user=myname --password=mypassword mydb >mydb_backup.sql
Windows上:
Linux上:
mysqldump --default-character-set=gb2312 --user=myname --password=mypassword mydb >mydb_backup.sql
Windows脚本自动登陆
D:\MySql\bin>mysql --user=myname --password=mypassword --default-character-set=gbk --host=192.168.0.17
posted on 2005-12-20 15:56
java小记 阅读(549)
评论(0) 编辑 收藏