apt-get install 安装的,不是源码包安装的mysql
1 修改mysql的配置文件
/etc/mysql/conf.d/mysql.cnf
在[mysql]的下方加入如下语句:(注:这个文件下没有配置,只有【mysql】)
no-auto-rehash
default-character-set=utf8
/etc/mysql/mysql.conf.d/mysqld.cnf
在[mysqld]下加入
socket = /var/run/mysqld/mysqld.sock
port = 3306
character-set-server=utf8 (这里是server,之前有的版本是set)
重启mysql: sudo /etc/init.d/mysql restart
查看字符集
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 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
设置之后如果之前的数据库已经创建了,只能删除重新创建了。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!