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;
时间: 2024-10-10 08:58:51

CentOS修改Mysql字符集的相关文章

centos修改mysql密码或者进入mysql后解决Access denied for user ''@'localhost' to database 'mysql错误

原因是MySQL的密码有问题 用mysql匿名用户可以进入数据库,但是看不见mysql数据库. 解决办法:具体操作步骤:关闭mysql:# service mysqld stop然后:# mysqld_safe --skip-grant-tables开启另一个终端并启动mysql:# service mysqld startmysql -u rootmysql> use mysqlmysql> UPDATE user SET Password=PASSWORD('root') WHERE us

修改Mysql字符集

第一种 一.修改my.ini配置文件(MySQL配置文件) character_set_server = utf8 #设置字符集 重启mysql数据库服务 查看当前数据库字符集 show VARIABLES like 'character%'; 二.修改数据库字符集 alter database 数据库名 character set utf8; ps:修改完数据库字符集,需要重启MySQL数据库. 三.修改表字符集 ALTER TABLE 表名 DEFAULT CHARACTER SET utf

CentOS查看和修改MySQL字符集

通过以下命令查看了MySQL的字符集 连接上mysql服务,输入以下命令 mysql>show variables like 'character_set%'; 显示如下: 为了让MySQL支持中文,需要把字符集改变成UTF8, 方法如下: 1. 打开vi /etc/my.cnf 2. 修改成如下内容,保存 [client] port=3306 socket=/var/lib/mysql/mysql.sock default-character-set=utf8 [mysqld] datadir

CentOS 查看和修改 MySQL 字符集

客户提供了MySQL的环境,但是不支持中文, 通过以下命令查看了MySQL的字符集 连接上 mysql 服务,输入以下命令 mysql> show variables like 'character_set%'; 显示如下: +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+-------------------------

centos修改oracle字符集

1.首先以sysdba的身份登录上去 conn /as sysdba2.关闭数据库shutdown immediate;3.以mount打来数据库,startup mount4.设置session SQL>ALTER SYSTEM ENABLE RESTRICTED SESSION;SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;5.启动数据库alter databas

CentOS 修改Mysql的root密码

1.知道密码 第一次登陆(无密码) mysqladmin -u root password NEWPASSWORD 修改过密码 mysqladmin -u root -p 'oldpassword' password 'newpassword' 2.忘记密码 编辑MySQL配置文件my.cnf vi /etc/my.cnf #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables [mysqld] skip-grant-tables 重启服务 service mysql

CENTOS设置MYSQL字符集

vim etc/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 ri

CentOS修改MySql数据库目录datadir

service mysqld stop        //停止mysql服务 cp -rf /var/lib/mysql /home/data     //复制默认的mysql数据库目录 chown -R mysql:mysql /home/data   //给新的目录授权 //修改my.cnf, 为确保没问题, 可以将以前的配置注释掉或者cp一份 vi /etc/my.cnf datadir=/home/data socket=/home/data/mysql.sock //修改mysqld

修改mysql字符集为utf8

#在[client]字段添加 [client] default-character-set=utf8 #在[mysqld]字段添加 [mysqld] character-set-server=utf8 #在[mysql]字段添加 [mysql] default-character-set=utf8 #修改完成后重启mysql ~$ sudo /etc/init.d/mysql restart #查看效果 mysql> show variables like '%char%'; +--------