首页 > 代码库 > ubuntu mysql 中文乱码解决

ubuntu mysql 中文乱码解决


在CSDN上看到的一个方法:

http://blog.csdn.net/zht666/article/details/8783396


其实就是在创建数据库的时候指定默认编码,我在我的电脑上试了一下,发现它自动生成的命令是:


CREATE SCHEMA `new_schema` DEFAULT CHARACTER SET utf8 ;
那么我在命令行中新建数据库的代码为:
create database default character utf8;
如下是我的插入和查询结果:



mysql> select database();
+------------+
| database() |
+------------+
| lamp_test  |
+------------+
1 row in set (0.00 sec)

mysql> show tables;
+---------------------+
| Tables_in_lamp_test |
+---------------------+
| student             |
+---------------------+
1 row in set (0.00 sec)

mysql> desc student;
+-------+------------------+------+-----+---------+-------+
| Field | Type             | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| name  | varchar(15)      | NO   |     | NULL    |       |
| age   | int(10) unsigned | NO   |     | NULL    |       |
| sex   | varchar(5)       | NO   |     | NULL    |       |
+-------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> insert into student values    #插入中文
    -> (‘小代码‘,23,‘男‘);
Query OK, 1 row affected (0.06 sec)

mysql> select * from student;  #显示中文
+-----------+-----+-----+
| name      | age | sex |
+-----------+-----+-----+
| 小代码    |  23 | 男  |    //已经正常显示
+-----------+-----+-----+
1 row in set (0.00 sec)

mysql>




ubuntu mysql 中文乱码解决