胖蔡说技术
随便扯扯

mysql中设置数据库默认创建的编码格式

说明

这是以前遇到mysql编码问题是记录的博文,先将其整合添加。文中所述问题以及解决问题的系统环境为 Ubuntu 14.04

操作

  • 修改配置文件 Mysql 的配置文件在Ubuntu 中的位置为

/etc/mysql/my.cnf

如下所示:

 #
 # The MySQL database server configuration file.
 #
 # You can copy this to one of:
 # - "/etc/mysql/my.cnf" to set global options,
 # - "~/.my.cnf" to set user-specific options.
 # 
 # One can use all long options that the program supports.
 # Run program with --help to get a list of available options and with
 # --print-defaults to see which it would actually understand and use.
 #
 # For explanations see
 # http://dev.mysql.com/doc/mysql/en/server-system-variables.html

 #
 # * IMPORTANT: Additional settings that can override those from this file!
 #   The files must end with '.cnf', otherwise they'll be ignored.
 #

 !includedir /etc/mysql/conf.d/
 !includedir /etc/mysql/mysql.conf.d/
 #添加编码配置
 [mysqld]
     default-character-set=utf8
 
 [client]
     default-character-set=utf8

如上,这是mysql的全局配置文件,可在其中添加编码配置设置。

  • 重启mysql服务 通过shell重启mysql命令
 $ sudo /etc/init.d/mysql restart
  • 验证编码 设置编码配置后,我们需要验证配置是否成功,可通过shell进入mysql应用进行查询验证,如下:
 $ mysql -u root -p

variables
mysql> show variables like ‘char%’;
±-------------------------±---------------------------+
| Variable_name | Value |
±-------------------------±---------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
±-------------------------±---------------------------+
8 rows in set (0.01 sec) mysql>

如上就完成了MySQL设置默认编码格式。

赞(0) 打赏
转载请附上原文出处链接:胖蔡说技术 » mysql中设置数据库默认创建的编码格式
分享到: 更多 (0)

请小编喝杯咖啡~

支付宝扫一扫打赏

微信扫一扫打赏