码迷,mamicode.com
首页 > 数据库 > 详细

CentOS修改Mysql字符集

时间:2017-05-18 11:25:06      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:com   roo   security   link   grant   variable   show   sql   常用   

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字符集

标签:com   roo   security   link   grant   variable   show   sql   常用   

原文地址:http://www.cnblogs.com/ScvQ/p/6871714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!