CentOS修改Mysql字符集
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS修改Mysql字符集相关的知识,希望对你有一定的参考价值。
1、mysql>show variables like ‘character_set%‘;
显示如下:
+--------------------------+----------------------------+ | 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/share/mysql/charsets/ | +--------------------------+----------------------------+
2、备份my.cnf cp /etc/my.cnf /etc/my.cnf.bak
3、修改my.cnf,结果如下
[client] port=3306 socket=/var/lib/mysql/mysql.sock default-character-set=utf8 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 character-set-server=utf8 [mysql] no-auto-rehash default-character-set=utf8 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
4、重启mysql服务 sudo service mysqld restart
5、mysql>show variables like ‘character_set%‘;
进入mysql控制台后,执行以下命令
修改默认字符集 1.1修改服务器默认字符集 set character_set_server=utf8 1.2修改数据库字符集 set character_set_database=utf8; 1.3修改数据库客户端字符集 set character_set_client=utf8; 1.4修改连接默认字符集 set character_set_connection=utf8
修改已经存在库的字符集 2.1修改存在数据库的字符集 alter database mydb character set utf8; 2.2修改存在表的字符集 alter table mytable default character set utf8
结果如下:
+--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+
6、其他一些常用命令
设置密码 use mysql; update user set password=password(‘密码‘) where user=‘root‘; flush privileges;
授权
grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘ with grant option;
以上是关于CentOS修改Mysql字符集的主要内容,如果未能解决你的问题,请参考以下文章
修改MySQL密码报错“ERROR 1819 (HY000): Your password does not satisfy the current policy requirements“(代码片段