centos7中mysql不能输入中文问题的解决

Posted 梦中琴歌

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7中mysql不能输入中文问题的解决相关的知识,希望对你有一定的参考价值。

首先在数据库里面输入

mysql> show variables like‘%char%‘
    -> ;
+--------------------------------------+----------------------------+
| Variable_name                        | Value                      |
+--------------------------------------+----------------------------+
| character_set_client                 | utf8                       |
| character_set_connection             | utf8                       |
| character_set_database               | latin1                     |
| character_set_filesystem             | binary                     |
| character_set_results                | utf8                       |
| character_set_server                 | latin1                     |
| character_set_system                 | utf8                       |
| character_sets_dir                   | /usr/share/mysql/charsets/ |
| validate_password_special_char_count | 1                          |
+--------------------------------------+----------------------------+
9 rows in set (0.00 sec)

mysql> set character_set_database=utf8;                   #更改编码属性
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> set character_set_server=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> set character_set_client=gbk;
Query OK, 0 rows affected (0.00 sec)

mysql> set character_set_connection=gbk;
Query OK, 0 rows affected (0.00 sec)

mysql> set character_set_client=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> set character_set_connection=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like‘%char%‘
    -> ;
+--------------------------------------+----------------------------+
| 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/ |
| validate_password_special_char_count | 1                          |
+--------------------------------------+----------------------------+
9 rows in set (0.00 sec)

mysql> use test1
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> showtables
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘showtables‘ at line 1
mysql> show tables;
+-----------------+
| Tables_in_test1 |
+-----------------+
| address         |
| authors         |
| book_m2m_author |
| books           |
| customer        |
| student         |
| study_record    |
+-----------------+
7 rows in set (0.00 sec)

mysql> insert into books (name) value(‘我‘);
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘;‘ at line 1
mysql> insert into books (name) value(‘我‘);
ERROR 1366 (HY000): Incorrect string value: ‘\xE6\x88\x91‘ for column ‘name‘ at row 1
mysql> alter table books convert to character set utf8;           #将数据表的编码方式改成utf8
Query OK, 3 rows affected (0.02 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> insert into books (name) value(‘我‘);
Query OK, 1 row affected (0.01 sec)

mysql> select * from books;
+----+------+----------+
| id | name | pub_date |
+----+------+----------+
|  1 | bbu1 | NULL     |
|  2 | bbu2 | NULL     |
|  3 | bbu3 | NULL     |
|  4 | 我   | NULL     |
+----+------+----------+
4 rows in set (0.00 sec)

mysql> select * from books;
+----+--------------+----------+
| id | name         | pub_date |
+----+--------------+----------+
|  1 | bbu1         | NULL     |
|  2 | bbu2         | NULL     |
|  3 | bbu3         | NULL     |
|  4 | 我           | NULL     |
|  5 | 我的世界     | NULL     |
+----+--------------+----------+
5 rows in set (0.00 sec)

mysql> 

 

以上是关于centos7中mysql不能输入中文问题的解决的主要内容,如果未能解决你的问题,请参考以下文章

centos7编译安装MySQL无法启动解决办法

centos7编译安装MySQL无法启动解决办法

centos7编译安装MySQL无法启动解决办法

CentOS7下安装mysql 以及小问题的解决方案

解决Centos 7不能联网且输入ifconfig出现command not found

解决 MySQL 数据库不能输入汉字问题