1、linux mysql 永久修改 字符集linux mysql 永久修改 字符集1.查找MySQL的cnf文件的位置find / -iname *.cnf -print/usr/share/mysql/my-innodb-heavy-4G.cnf /usr/share/mysql/my-f/usr/share/mysql/my-f/usr/share/mysql/my-f/usr/share/mysql/my-f/usr/share/texmf/web2c/f/usr/share/texmf/web2c/f/usr/share/texmf/web2c/f/usr/share/texmf/tex
2、/xmltex/f/usr/share/texmf/tex/jadetex/f/usr/share/doc/MySQL-server-community-5.1.22/my-innodb-heavy-4G.cnf/usr/share/doc/MySQL-server-community-5.1.22/my-f/usr/share/doc/MySQL-server-community-5.1.22/my-f/usr/share/doc/MySQL-server-community-5.1.22/my-f/usr/share/doc/MySQL-server-community-5.1.22/my
3、-f2. 拷贝 f、my-f、my-f、my-innodb-heavy-4G.cnf其中的一个到/etc下,命名为f cp /usr/share/mysql/my-f /etc/f3. 修改fvi /etc/f在client下添加default-character-set=utf8在mysqld下添加default-character-set=utf84.重新启动MySQL rootbogon # /etc/rc.d/init.d/mysql restartShutting down MySQL 确定 Starting MySQL. 确定 rootbogon # mysql -u root -
4、pEnter password:Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 1Server version: 5.1.22-rc-community-log MySQL Community Edition (GPL)Type help; or h for help. Type c to clear the buffer.5.查看字符集设置mysql show variables like collation_%;+-+-+| Variable_name | Value |+
5、-+-+| collation_connection | utf8_general_ci | collation_database | utf8_general_ci | collation_server | utf8_general_ci |+-+-+3 rows in set (0.02 sec)mysql show variables like character_set_%;+-+-+| Variable_name | Value |+-+-+| character_set_client | utf8 | character_set_connection | utf8 | charac
6、ter_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.02 sec)参考: ubuntu 10.04 mySql 启动,停止,重启启动:sudo /etc/init.d/mysql start 停止:sud
7、o /etc/init.d/mysql stop 重启:sudo /etc/init.d/mysql restart注意:从windows下拷贝过来的文件在linux下不能直接加入数据库,因为字符集不一样,这样打开即使显示是中文也不能在数据库中显示,要把文件拷贝进linux的另一个文件中转换字符才可以。MySQL 乱码的根源是的 MySQL 字符集设置不当的问题,本文汇总了有关查看 MySQL 字符集的命令。包括查看 MySQL 数据库服务器字符集、查看 MySQL 数据库字符集,以及数据表和字段的字符集、当前安装的 MySQL 所支持的字符集等。 一、查看 MySQL 数据库服务器和数据库字
8、符集。 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 | utf8 |. -
9、 服务器字符集| character_set_system | utf8 |.| character_sets_dir | D:MySQL Server 5.0sharecharsets |.+-+-+-二、查看 MySQL 数据表(table) 的字符集。 mysql show table status from sqlstudy_db like %countries%;+-+-+-+-+-+-+-| Name | Engine | Version | Row_format | Rows | Collation |.+-+-+-+-+-+-+-| countries | InnoDB | 1
10、0 | Compact | 11 | utf8_general_ci |.+-+-+-+-+-+-+-三、查看 MySQL 数据列(column)的字符集。 mysql show full columns from countries;+-+-+-+-| Field | Type | Collation | .+-+-+-+-| countries_id | int(11) | NULL | .| countries_name | varchar(64) | utf8_general_ci | .| countries_iso_code_2 | char(2) | utf8_general_c
11、i | .| countries_iso_code_3 | char(3) | utf8_general_ci | .| address_format_id | int(11) | NULL | .+-+-+-+-四、查看当前安装的 MySQL 所支持的字符集。 mysql show charset;mysql show char set;+-+-+-+-+| Charset | Description | Default collation | Maxlen |+-+-+-+-+| big5 | Big5 Traditional Chinese | big5_chinese_ci | 2 |
12、 dec8 | DEC West European | dec8_swedish_ci | 1 | cp850 | DOS West European | cp850_general_ci | 1 | hp8 | HP West European | hp8_english_ci | 1 | koi8r | KOI8-R Relcom Russian | koi8r_general_ci | 1 | latin1 | cp1252 West European | latin1_swedish_ci | 1 | latin2 | ISO 8859-2 Central European | lat
13、in2_general_ci | 1 | swe7 | 7bit Swedish | swe7_swedish_ci | 1 | ascii | US ASCII | ascii_general_ci | 1 | ujis | EUC-JP Japanese | ujis_japanese_ci | 3 | sjis | Shift-JIS Japanese | sjis_japanese_ci | 2 | hebrew | ISO 8859-8 Hebrew | hebrew_general_ci | 1 | tis620 | TIS620 Thai | tis620_thai_ci | 1
14、 | euckr | EUC-KR Korean | euckr_korean_ci | 2 | koi8u | KOI8-U Ukrainian | koi8u_general_ci | 1 | gb2312 | GB2312 Simplified Chinese | gb2312_chinese_ci | 2 | greek | ISO 8859-7 Greek | greek_general_ci | 1 | cp1250 | Windows Central European | cp1250_general_ci | 1 | gbk | GBK Simplified Chinese |
15、 gbk_chinese_ci | 2 | latin5 | ISO 8859-9 Turkish | latin5_turkish_ci | 1 | armscii8 | ARMSCII-8 Armenian | armscii8_general_ci | 1 | utf8 | UTF-8 Unicode | utf8_general_ci | 3 | ucs2 | UCS-2 Unicode | ucs2_general_ci | 2 | cp866 | DOS Russian | cp866_general_ci | 1 | keybcs2 | DOS Kamenicky Czech-S
16、lovak | keybcs2_general_ci | 1 | macce | Mac Central European | macce_general_ci | 1 | macroman | Mac West European | macroman_general_ci | 1 | cp852 | DOS Central European | cp852_general_ci | 1 | latin7 | ISO 8859-13 Baltic | latin7_general_ci | 1 | cp1251 | Windows Cyrillic | cp1251_general_ci |
17、1 | cp1256 | Windows Arabic | cp1256_general_ci | 1 | cp1257 | Windows Baltic | cp1257_general_ci | 1 | binary | Binary pseudo charset | binary | 1 | geostd8 | GEOSTD8 Georgian | geostd8_general_ci | 1 | cp932 | SJIS for Windows Japanese | cp932_japanese_ci | 2 | eucjpms | UJIS for Windows Japanese
18、| eucjpms_japanese_ci | 3 |+-+-+-+-+以上查看 MySQL 字符集命令,适用于 Windows & Linux。 1.查找MySQL的cnf文件的位置find / -iname *.cnf -print/usr/share/mysql/my-innodb-heavy-4G.cnf /usr/share/mysql/my-f/usr/share/mysql/my-f/usr/share/mysql/my-f/usr/share/mysql/my-f/usr/share/texmf/web2c/f/usr/share/texmf/web2c/f/usr/share
19、/texmf/web2c/f/usr/share/texmf/tex/xmltex/f/usr/share/texmf/tex/jadetex/f/usr/share/doc/MySQL-server-community-5.1.22/my-innodb-heavy-4G.cnf/usr/share/doc/MySQL-server-community-5.1.22/my-f/usr/share/doc/MySQL-server-community-5.1.22/my-f/usr/share/doc/MySQL-server-community-5.1.22/my-f/usr/share/do
20、c/MySQL-server-community-5.1.22/my-f2. 拷贝 f、my-f、my-f、my-innodb-heavy-4G.cnf其中的一个到/etc下,命名为f cp /usr/share/mysql/my-f /etc/f3. 修改fvi /etc/f在client下添加default-character-set=utf8在mysqld下添加default-character-set=utf84.重新启动MySQL rootbogon # /etc/rc.d/init.d/mysql restartShutting down MySQL 确定 Starting MyS
21、QL. 确定 rootbogon # mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 1Server version: 5.1.22-rc-community-log MySQL Community Edition (GPL)Type help; or h for help. Type c to clear the buffer.5.查看字符集设置mysql show variables like collation
22、_%;+-+-+| Variable_name | Value |+-+-+| collation_connection | utf8_general_ci | collation_database | utf8_general_ci | collation_server | utf8_general_ci |+-+-+3 rows in set (0.02 sec)mysql show variables like character_set_%;+-+-+| Variable_name | Value |+-+-+| character_set_client | utf8 | charac
23、ter_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.02 sec)mysql其他的一些设置方法: 修改数据库的字符集 mysqluse mydbmysqlalter database mydb character set utf-8;创建数据库指定数据库的字符集mysqlcr
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1