标签:
今天在学习mysql的时候发现了我的编码是 : latin1 的情况,应该是不支持中文,虽然还没有尝试过,先给他修改了吧。
先查询一下默认的情况:
mysql> show variables like ‘%collation%‘; 从网上找的查询命令,虽然还不知道这个 collation是干嘛用的
+--------------------------+----------------------------+
| Variable_name | Value |
+---------------------------+----------------------------+
| collation_connection | latin1_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+--------------------------+------------------------------+
3 rows in set (0.01 sec)
然后再执行了:
mysql> SHOW VARIABLES LIKE ‘%CHARACTER%‘; 这个应该就是字符的格式的意思
+---------------------------------+------------------------------------------------+
| Variable_name | Value |
+---------------------------------+------------------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/mysql/charsets/ |
+--------------------------+----------------------------------------+
8 rows in set (0.00 sec)
基本上以上全是拉丁的,进行修改:
找到 my.cnf 配置文件进行编辑:
--在 [mysqld] 标签下加上以下内容:
default-character-set = utf8
character_set_server = utf8
保存退出!
重启mysql服务,我的重启办法是比较笨的,杀死进程!
root@b-ThinkPad-X230s:/usr/local/mysql/bin# ps aux | grep "mysql"
root 3945 0.0 0.0 4476 1664 ? S 13:52 0:00 /bin/sh ./mysqld_safe --user=root
root 4062 0.0 0.4 423308 33792 ? Sl 13:52 0:03 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=root --log-error=/usr/local/mysql/var/b-ThinkPad-X230s.err --pid-file=/usr/local/mysql/var/b-ThinkPad-X230s.pid --socket=/tmp/mysql.sock --port=3306
root 13262 0.0 0.0 13712 2144 pts/18 S+ 16:11 0:00 grep --color=auto mysql
root@b-ThinkPad-X230s:/usr/local/mysql/bin# kill -9 3945
root@b-ThinkPad-X230s:/usr/local/mysql/bin# kill -9 4062
杀完了,重新运行:
root@b-ThinkPad-X230s:/usr/local/mysql/bin# ./mysqld_safe --user=root
151218 16:12:23 mysqld_safe Logging to ‘/usr/local/mysql/var/b-ThinkPad-X230s.err‘.
151218 16:12:23 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
再执行上面的查询命令:
mysql> show variables like ‘%character%‘;
+-----------------------------------+----------------------------------------+
| Variable_name | Value |
+----------------------------------+--------------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/mysql/charsets/ |
+------------------------------------+----------------------------------------------+
8 rows in set (0.01 sec)
发现变化了的有:
character_set_database
character_set_server
还有几个没有变,接着改:
character_set_client;character_set_connection;character_set_results
按照网上的教程:
注意:如果此标签下已经存在“default-character-set=GBK”类似的内容,只需修改即可。
--在 [mysql] 标签下加上一行
default-character-set = utf8
--在 [mysql.server]标签下加上一行
default-character-set = utf8
--在 [mysqld_safe]标签下加上一行
default-character-set = utf8
--在 [client]标签下加上一行
default-character-set = utf8
我的my.cnf没有那么多区域,比如:[mysqld_safe][mysql.server] 这些我后来手动添加!
添加完成,然后重启,登录,检查:
结果不尽人意!
mysql> SHOW VARIABLES LIKE ‘%CHARACTER%‘;
+--------------------------+----------------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/mysql/charsets/ |
+--------------------------+----------------------------------------+
8 rows in set (0.00 sec)
索性把刚才的操作删除!
标签:
原文地址:http://www.cnblogs.com/persistcat/p/5057467.html