Liunx如何修改MySQL字符集
2019/10/10/17:36:39 阅读:1814 来源:谷歌SEO算法 标签:
1号店SEO
今天发现在linux中我mysql数据库中的中文全部都是乱码了,我查看了mysql字符集默认为latin1了,下面我来给大家介绍几种修改方法.
Linux下使用service mysql restart命令重启MySql服务,新建的数据库都会使用到这个字符集做为默认字符集,修改MySql服务器各个数据库的字符集,如果在设置服务器字符集之前,存在了数据库,需要更改数据库的字符集,代码如下:
use datatable_name;
alter database character set gbk;
改完字符集的其它问题,字符集修改好了以后发现使用存储过程做新增操作时,还会出现中文乱码,但是直接写SQL语句就不会出现乱码.
查看字符集设置,代码如下:
- mysql>showvariableslike'collation_%';
- +----------------------+-----------------+
- |Variable_name|Value|
- +----------------------+-----------------+
- |collation_connection|utf8_general_ci|
- |collation_database|utf8_general_ci|
- |collation_server|utf8_general_ci|
- +----------------------+-----------------+
- 3rowsinset(0.02sec)
- mysql>showvariableslike'character_set_%';
- +--------------------------+----------------------------+
- |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|
- |character_set_system|utf8|
- |character_sets_dir|/usr/share/mysql/charsets/|
- +--------------------------+----------------------------+
- 8rowsinset(0.02sec)
- mysql>
1.查找MySQL的cnf文件的位置,代码如下:
- find/-iname'*.cnf'-print
- /usr/share/mysql/my-innodb-heavy-4G.cnf
- /usr/share/mysql/my-large.cnf
- /usr/share/mysql/my-small.cnf
- /usr/share/mysql/my-medium.cnf
- /usr/share/mysql/my-huge.cnf
- /usr/share/texmf/web2c/texmf.cnf
- /usr/share/texmf/web2c/mktex.cnf
- /usr/share/texmf/web2c/fmtutil.cnf
- /usr/share/texmf/tex/xmltex/xmltexfmtutil.cnf
- /usr/share/texmf/tex/jadetex/jadefmtutil.cnf
- /usr/share/doc/MySQL-server-community-5.1.22/my-innodb-heavy-4G.cnf
- /usr/share/doc/MySQL-server-community-5.1.22/my-large.cnf
- /usr/share/doc/MySQL-server-community-5.1.22/my-small.cnf
- /usr/share/doc/MySQL-server-community-5.1.22/my-medium.cnf
- /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,代码如下:
- [root@bogon~]#/etc/rc.d/init.d/mysqlrestart
- ShuttingdownMySQL[确定]
- StartingMySQL.[确定]
- [root@bogon~]#mysql-uroot-p
- Enterpassword://phpfensi.com
- WelcometotheMySQLmonitor.Commandsendwith;org.
- YourMySQLconnectionidis1
- Serverversion:5.1.22-rc-community-logMySQLCommunityEdition(GPL)
- Type'help;'or'h'forhelp.Type'c'toclearthebuffer.
热门评论