Liunx如何修改MySQL字符集

木木老贼 互联网营销达人~

今天发现在linux中我mysql数据库中的中文全部都是乱码了,我查看了mysql字符集默认为latin1了,下面我来给大家介绍几种修改方法.

Linux下使用service mysql restart命令重启MySql服务,新建的数据库都会使用到这个字符集做为默认字符集,修改MySql服务器各个数据库的字符集,如果在设置服务器字符集之前,存在了数据库,需要更改数据库的字符集,代码如下:

use datatable_name;

alter database character set gbk;

改完字符集的其它问题,字符集修改好了以后发现使用存储过程做新增操作时,还会出现中文乱码,但是直接写SQL语句就不会出现乱码.

查看字符集设置,代码如下:

  1. mysql>showvariableslike'collation_%';
  2. +----------------------+-----------------+
  3. |Variable_name|Value|
  4. +----------------------+-----------------+
  5. |collation_connection|utf8_general_ci|
  6. |collation_database|utf8_general_ci|
  7. |collation_server|utf8_general_ci|
  8. +----------------------+-----------------+
  9. 3rowsinset(0.02sec)
  10. mysql>showvariableslike'character_set_%';
  11. +--------------------------+----------------------------+
  12. |Variable_name|Value|
  13. +--------------------------+----------------------------+
  14. |character_set_client|utf8|
  15. |character_set_connection|utf8|
  16. |character_set_database|utf8|
  17. |character_set_filesystem|binary|
  18. |character_set_results|utf8|
  19. |character_set_server|utf8|
  20. |character_set_system|utf8|
  21. |character_sets_dir|/usr/share/mysql/charsets/|
  22. +--------------------------+----------------------------+
  23. 8rowsinset(0.02sec)
  24. mysql>

1.查找MySQL的cnf文件的位置,代码如下:

  1. find/-iname'*.cnf'-print
  2. /usr/share/mysql/my-innodb-heavy-4G.cnf
  3. /usr/share/mysql/my-large.cnf
  4. /usr/share/mysql/my-small.cnf
  5. /usr/share/mysql/my-medium.cnf
  6. /usr/share/mysql/my-huge.cnf
  7. /usr/share/texmf/web2c/texmf.cnf
  8. /usr/share/texmf/web2c/mktex.cnf
  9. /usr/share/texmf/web2c/fmtutil.cnf
  10. /usr/share/texmf/tex/xmltex/xmltexfmtutil.cnf
  11. /usr/share/texmf/tex/jadetex/jadefmtutil.cnf
  12. /usr/share/doc/MySQL-server-community-5.1.22/my-innodb-heavy-4G.cnf
  13. /usr/share/doc/MySQL-server-community-5.1.22/my-large.cnf
  14. /usr/share/doc/MySQL-server-community-5.1.22/my-small.cnf
  15. /usr/share/doc/MySQL-server-community-5.1.22/my-medium.cnf
  16. /usr/share/doc/MySQL-server-community-5.1.22/my-huge.cnf

2.拷贝,代码如下:

small.cnf、my-medium.cnf、my-huge.cnf、my-innodb-heavy-4G.cnf其中的一个到/etc下,命名为my.cnf

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

3.修改my.cnf,代码如下:

vi /etc/my.cnf

在[client]下添加

default-character-set=utf8

在[mysqld]下添加

default-character-set=utf8

4.重新启动MySQL,代码如下:

  1. [root@bogon~]#/etc/rc.d/init.d/mysqlrestart
  2. ShuttingdownMySQL[确定]
  3. StartingMySQL.[确定]
  4. [root@bogon~]#mysql-uroot-p
  5. Enterpassword://phpfensi.com
  6. WelcometotheMySQLmonitor.Commandsendwith;org.
  7. YourMySQLconnectionidis1
  8. Serverversion:5.1.22-rc-community-logMySQLCommunityEdition(GPL)
  9. Type'help;'or'h'forhelp.Type'c'toclearthebuffer.

相关广告
  • Liunx如何修改MySQL字符集 Liunx如何修改MySQL字符集 Liunx如何修改MySQL字符集
相关阅读

Liunx如何修改MySQL字符集

2019/10/10 17:36:39 | 谷歌SEO算法 | 1号店SEO