Home > Database > Mysql Tutorial > MySQL查看与修改当前数据库编码的方法_MySQL

MySQL查看与修改当前数据库编码的方法_MySQL

PHP中文网
Release: 2016-05-27 13:44:37
Original
1151 people have browsed it

MySQL中,数据库的编码是一个相当重要的问题,有时候我们需要查看一下当前数据库的编码,甚至需要修改一下数据库编码。

查看当前数据库编码的SQL语句为:

mysql> use xxx
Database changed
mysql> 
show variables like 'character_set_database';
+------------------------+--------+
| Variable_name          | Value  |
+------------------------+--------+
| character_set_database | latin1 |
+------------------------+--------+
Copy after login

1 row in set (0.00 sec)

上面,我们先切换到xxx数据库下面来,然后使用SQL语句:show variables like 'character_set_database'; 来查看了xxx数据库的编码。查询得到的结果是latin1编码。

下面,我们来修改xxx数据库的编码,把它修改为gb2312。

mysql> alter database xxx CHARACTER SET gb2312;Query OK, 1 row affected (0.00 sec)
mysql> show variables like 'character_set_database';
+------------------------+--------+
| Variable_name     | Value  |
+------------------------+--------+
| character_set_database | gb2312 |
+------------------------+--------+
Copy after login

1 row in set (0.00 sec)

这里同样做了两件事情:
1、使用SQL语句:alter database xxx CHARACTER SET gb2312; 把xxx数据库的编码设置为了gb2312.
2、再次使用show variables like 'character_set_database'; 来确认一下当前xxx是什么编码。经过确认,数据库编码已经修改为gb2312了。

3、当然很多情况下都是修改为utf-8编码

以上就是MySQL查看与修改当前数据库编码的方法_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template