mysql> select * from books;
+-----+---------------------------------+---------+-------------+-------+------------+--------+-------------+
| bId | bName | bTypeId | publishing | price | pubDate | author | ISBN |
+-----+---------------------------------+---------+-------------+-------+------------+--------+-------------+
| 1 | ??????? | 2 | ???????? | 34 | 2004-10-01 | ?? | 7505380796 |
| 2 | ??????? | 6 | ??????? | 41 | 2002-07-01 | ??? | 7121010925 |
| 3 | ????????asp | 2 | ????????? | 43 | 2005-02-01 | ?? | 75053815x |
| 4 | pagemaker 7.0?????? | 9 | ??????? | 43 | 2005-01-01 | ??? | 7121008947 |
| 5 | ???????? | 6 | ????????? | 44 | 2003-06-29 | ??? | 7120000233 |
| 6 | Dreamweaver 4????? | 2 | ??????? | 44 | 2004-06-01 | ??? | 7505397699 |
1.确认并设置MySql的数据库的编码(注意下面橘色字体)
mysql> status
--------------
mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1 Connection id: 2
Current database: school
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.1.73 Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 1 min 8 sec Threads: 1 Questions: 13 Slow queries: 0 Opens: 17 Flush tables: 1 Open tables: 10 Queries per second avg: 0.191
--------------
2.修改方法
首先进入数据库mysql -uroot -p123
mysql>use school
mysql> alter database school character set utf8;
mysql> alter database school character set utf8 collate utf8_general_ci;
mysql> alter table books character set utf8 collate utf8_general_ci; 3.vim /etc/my.conf //编辑修改mysql配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server = utf8 [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid [client]
default-character-set=utf8 [mysql]
default-character-set=utf8
4.以上保存后重启数据库
[root@orange ~]# /etc/init.d/mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定] 5.进入mysql查看字符集
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/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec) mysql> show variables like "%colla%";
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
mysql> select * from books;
+-----+---------------------------------------------------------+---------+-----------------------------------+-------+------------+-----------+-------------+
| bId | bName | bTypeId | publishing | price | pubDate | author | ISBN |
+-----+---------------------------------------------------------+---------+-----------------------------------+-------+------------+-----------+-------------+
| 1 | 网站制作直通车 | 2 | 电脑爱好者杂志社 | 34 | 2004-10-01 | 苗壮 | 7505380796 |
| 2 | 黑客与网络安全 | 6 | 航空工业出版社 | 41 | 2002-07-01 | 白立超 | 7121010925 |
| 3 | 网络程序与设计-asp | 2 | 北方交通大学出版社 | 43 | 2005-02-01 | 王玥 | 75053815x |
| 4 | pagemaker 7.0短期培训教程 | 9 | 中国电力出版社 | 43 | 2005-01-01 | 孙利英 | 7121008947 |
| 5 | 黑客攻击防范秘笈 | 6 | 北京腾图电子出版社 | 44 | 2003-06-29 | 赵雷雨 | 7120000233 |
| 6 | Dreamweaver 4入门与提高 | 2 | 清华大学出版社 | 44 | 2004-06-01 | 岳玉博 | 7505397699 |

一、避免创建数据库及表出现中文乱码和查看编码方法
1、创建数据库的时候:CREATE DATABASE `test`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';
2、建表的时候 CREATE TABLE `database_user` (
`ID` varchar(40) NOT NULL default '',
`UserID` varchar(40) NOT NULL default '',
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

即建库和建表时都使用相同的编码格式。  

查看school数据库的编码格式:

mysql> show create database school;
+----------+-----------------------------------------------------------------+
| Database | Create Database |
+----------+-----------------------------------------------------------------+
| school | CREATE DATABASE `school` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-----------------------------------------------------------------+
1 row in set (0.00 sec)

 查看books表的编码格式

 mysql> use school
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> show create table books;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| books | CREATE TABLE `books` (
`bId` int(4) NOT NULL AUTO_INCREMENT,
`bName` varchar(255) DEFAULT NULL,
`bTypeId` enum('1','2','3','4','5','6','7','8','9','10') DEFAULT NULL,
`publishing` varchar(255) DEFAULT NULL,
`price` int(4) DEFAULT NULL,
`pubDate` date DEFAULT NULL,
`author` varchar(30) DEFAULT NULL,
`ISBN` varchar(255) DEFAULT NULL,
PRIMARY KEY (`bId`)
) ENGINE=MyISAM AUTO_INCREMENT=45 DEFAULT CHARSET=utf8 |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MySQL数据库中文乱码问题的更多相关文章

  1. Mybatis插入MySQL数据库中文乱码

    Mybatis插入MySQL数据库中文乱码 在dataSource.properties配置文件中设置useUnicode=true&characterEncoding=utf-8编码即可. ...

  2. Django 连接mysql数据库中文乱码

    Django 连接mysql数据库中文乱码 2018年08月25日 20:55:15 可乐乐乐乐乐 阅读数:566   版本:CentOS6.8 python3.6.4 django1.8.2 数据库 ...

  3. mysql数据库 中文乱码

    看到一篇很好的文章,转录于此 中文乱码似乎是程序编写中永恒的一个话题和难点,就比如MySQL存取中文乱码,但我想做任何事情,都要有个思路才行,有了思路才知道如何去解决问题,否则,即使一时解决了问题,但 ...

  4. mysql数据库-中文乱码问题解决方案

    来自:http://www.2cto.com/database/201108/101151.html MySQL会出现中文乱码的原因不外乎下列几点: .server本身设定问题,例如还停留在latin ...

  5. java 保存到mysql数据库中文乱码

    <property name="jdbcUrl">jdbc:mysql://localhost:3306/company?useUnicode=true&cha ...

  6. 关于hibernate插入数据到mysql数据库中文乱码问题的解决

    要想解决这个问题就要找到问题的症结所在 1.首先将数据提交到action输出看action里的数据是不是中文乱码,结果很遗憾并不是这里的问题 2.设置数据库连接url: 3.打开mysql安装文件里的 ...

  7. DOS命令行操作MySQL数据库中文乱码问题解决

    我们在 dos 命令行操作中文时,会报错 ’); ERROR (HY000): Incorrect string value: '\xD5\xC5\xC8\xFD' for column 原因:因为 ...

  8. 解决navicate 连接mysql数据库中文乱码的问题

    以下均是ubuntu12.04为准 1.修改mysql的配置文件. 1.1.vi  /etc/mysql/my.conf找到[client]在其下面添加 default-character-set=u ...

  9. web项目数据存入mysql数据库中文乱码问题

    刚开始怀疑是项目中编码设置问题,发现在web.xml中已经有过设置:后来dubug显示数据在传输的过程中一切正常,怀疑是数据库编码问题,然后查看mysql编码: show variables like ...

随机推荐

  1. if控制器,如何传参。

  2. 记一次Spring boot集成mybatis错误修复过程 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

    最近自己写了一份代码签入到github,然后拉下来运行报下面的错误 Error starting ApplicationContext. To display the conditions repor ...

  3. java.net.URLEncoder对中文的编码和解码

    // java.net.URLEncoder对中文的编码和解码String str = URLEncoder.encode("测试字符串", "utf-8"); ...

  4. HTTP发展简史

    HTTP发展简史 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的 ...

  5. linux清理系统缓存

    Linux 内存优化. 1.清理前内存使用情况 free -m 2.开始清理 echo 1 > /proc/sys/vm/drop_caches 3.清理后内存使用情况 free -m 4.完成 ...

  6. Android.mk文件和Application.mk文件详解

    Android.mk文件和Application.mk文件详解 相同点:都是轻量级 Makefile(Makefile文件定义一些列指令,指定文件编译顺序,类似shell脚本) Application ...

  7. elasticsearch基础查询

    Es基础数据类型 string 字符串类型,es中最常用的类型,官方文档 比较重要的参数: index分析 analyzed(默认) not_analyzed no store存储 true 独立存储 ...

  8. pycharm 里运行 django 工程 You must either define the environment variable DJANGO_SETTINGS_MODULE 错误

    pycharm 里运行 django 工程出现错误(在命令行直接运行ok): django.core.exceptions.ImproperlyConfigured: Requested settin ...

  9. 爬虫之selenium模块;无头浏览器的使用

    一,案例 爬取站长素材中的图片:http://sc.chinaz.com/tupian/gudianmeinvtupian.html import requests from lxml import ...

  10. Odoo日历视图详解

    转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10826148.html 一:日历视图定义 根元素为<calendar>. 主要的属性有:    ...