mysql数据库中导入数据库无法显示中文,中文乱码(解决)Window/Linux

mysql -P 3306 -uroot -p

查看数据库编码

mysql> show variables like 'character%';


解决:重新建立数据库,重新设置mysql编码

在MySQL的安装目录下找到my.ini,如果没有就把my-medium.ini复制为一个my.ini即可, 
修改my.ini,在[client]和[mysqld]下面均加上

default-character-set=utf8

重启数据库!!

再来show variables like 'character%';


已经更改好了,让我再来新建数据库试试:

mysql> create database testConn;
Query OK, 1 row affected (0.00 sec)

mysql> use testConn;
Database changed


mysql> source c:/testConn.sql



mysql>  show variables like 'character%';
+--------------------------+----------------------------------------------+
| Variable_name            | Value                                        |
+--------------------------+----------------------------------------------+
| character_set_client     | gbk                                          |
| character_set_connection | gbk                                          |
| character_set_database   | gbk                                          |
| character_set_filesystem | binary                                       |
| character_set_results    | gbk                                          |
| character_set_server     | gbk                                          |
| character_set_system     | utf8                                         |
| character_sets_dir       | D:\PHPnow-1.5.6\MySQL-5.1.50\share\charsets\ |
+--------------------------+----------------------------------------------+
8 rows in set (0.00 sec)


mysql> show tables;
+--------------------+
| Tables_in_testconn |
+--------------------+
| student_table      |
| teacher_table      |
+--------------------+
2 rows in set (0.00 sec)

问题解决!!


 Linux安装Mysql后其默认编码如下:

(运行如下命令即可查看编码方式)

# mysql -u root -p

Enter password:

mysql > show variables like "character%";

编码显示:

+--------------------------+----------------------------+


| 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/ |
+--------------------------+----------------------------+

1.要修改编码方式则找到mysql安装目录下的配置文件(.cnf文件),一般至少有四个配置文件:mysql-huge.cnf mysql-medium.cnf  mysql-small.cnf mysql mysql-large.cnf  这四个配置文件我们只需拷贝其中一个文件到目录/etc下并重命名为my.cnf,若不拷贝到此目录下则重启Mysql后编码方式又回到默认方式,就是因为这个我整了半天。只要拷贝到/etc目录下就永久的修改了编码方式。

2.修改文件my.cnf:

找到客户端配置[client] 在www.linuxidc.com下面添加
default-character-set=utf8 默认字符集为utf8
在找到[mysqld] 添加
default-character-set=utf8 默认字符集为utf8

init_connect=SET NAMES 'utf8'

3.重启Mysql:

# service mysql restart

再查看编码方式即改为了所需编码方式,如下:

+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+





你可能感兴趣的:(MYSQL)