旗下导航:搜·么
当前位置:网站首页 > MySQL教程 > 正文

mysql怎么改字符编码?【MySQL教程】,mysql,字符编码

作者:搜教程发布时间:2019-12-01分类:MySQL教程浏览:28评论:0


导读:mysql命令行修正字符编码1、修正数据库字符编码mysql>alterdatabasemydbcharactersetutf8;2、建立数据库...

mysql命令行修正字符编码

1、修正数据库字符编码

mysql> alter database mydb character set utf8 ;

2、建立数据库时,指定数据库的字符编码

mysql> create database mydb character set utf8 ;

3、检察mysql数据库的字符编码

mysql> show variables like 'character%'; //查询当前mysql数据库的一切属性的字符编码
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | latin1                     |
| character_set_connection | latin1                     |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | latin1                     |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

4、修正mysql数据库的字符编码

修正字符编码必须要修正mysql的设置文件my.cnf,然后重启才见效

一般须要修正my.cnf的以下几个处所:

【client】下面,加上default-character-set=utf8,或许character_set_client=utf8

【mysqld】下面,加上character_set_server = utf8 ;

由于以上设置,mysql默许是latin1,假如仅仅是经由过程命令行客户端,mysql重启以后就不起作用了。

以下是客户端命令行修正体式格局,不引荐运用

mysql> set character_set_client=utf8 ;
mysql> set character_set_connection=utf8 ;
mysql> set character_set_database=utf8 ;
mysql> set character_set_database=utf8 ;
mysql> set character_set_results=utf8 ;
mysql> set character_set_server=utf8 ;
mysql> set character_set_system=utf8 ;
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| 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)

以上就是mysql怎么改字符编码?的细致内容,更多请关注ki4网别的相干文章!

标签:mysql字符编码


欢迎 发表评论: