﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Jerome Kwok〖旧日的足迹〗-文章分类-MySQL</title><link>http://www.blogjava.net/JeromeKwok/category/43885.html</link><description>仁者不忧，知者不惑，勇者不惧</description><language>zh-cn</language><lastBuildDate>Sat, 06 Feb 2010 11:46:18 GMT</lastBuildDate><pubDate>Sat, 06 Feb 2010 11:46:18 GMT</pubDate><ttl>60</ttl><item><title>MySql之5.0使用心得</title><link>http://www.blogjava.net/JeromeKwok/articles/311987.html</link><dc:creator>Jerome Kwok</dc:creator><author>Jerome Kwok</author><pubDate>Thu, 04 Feb 2010 07:53:00 GMT</pubDate><guid>http://www.blogjava.net/JeromeKwok/articles/311987.html</guid><wfw:comment>http://www.blogjava.net/JeromeKwok/comments/311987.html</wfw:comment><comments>http://www.blogjava.net/JeromeKwok/articles/311987.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/JeromeKwok/comments/commentRss/311987.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/JeromeKwok/services/trackbacks/311987.html</trackback:ping><description><![CDATA[<p><span style="font-family: Courier; font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;前两天很是使用了一把MySql，版本是5.0.27，对字符集的设置、存储过程的建立、触发器的建立颇有心得，现与大家分享实例。<br style="font-family: " />
<br style="font-family: " />
1、字符集的设置<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp;a、首先安装MySql5.0.27，注意！是setup安装，不是免安装版。（如何设置免安装版的字符集俺还不会）<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp;b、运行MySql Server Instance Configuration Wizard，在please select the default character set页面选择Menual Selected Default Character Set / Collation，并在Character Set:下拉框中选择gb2312（经测试，从MS SQL Server中导入中文字符是成功的。）<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp;c、然后启动MySql服务即可！<br style="font-family: " />
<br style="font-family: " />
2、存储过程的建立<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp;a、为了方便执行sql语句，我建议安装MySQL GUI Tools 5.0的可视化工具，十分方便！<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp;b、打开MySQL GUI Tools 5.0的MySql Query Browser工具，连接localhost，用户名为root，密码为空。<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp;c、选择File-〉New Script Tab<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp;d、在Script 1的Tab页中输入以下语句，选择Execute按钮执行即可。<br style="font-family: " />
<br style="font-family: " />
-- 建立数据库 sample ，并使用它<br style="font-family: " />
create database sample;<br style="font-family: " />
use sample;<br style="font-family: " />
<br style="font-family: " />
-- 建立一个表<br style="font-family: " />
<br style="font-family: " />
create table Msg (<br style="font-family: " />
&nbsp; MsgServiceId&nbsp;&nbsp;&nbsp; &nbsp;integer,<br style="font-family: " />
&nbsp; MsgTypeId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;integer,<br style="font-family: " />
&nbsp; MsgQueuedAt&nbsp;&nbsp; &nbsp;datetime,<br style="font-family: " />
&nbsp; MsgParam1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;varchar(60)&nbsp; NULL,<br style="font-family: " />
&nbsp; MsgId&nbsp;&nbsp;&nbsp; &nbsp;int NOT NULL auto_increment,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- 自增<br style="font-family: " />
&nbsp; PRIMARY KEY&nbsp; (`MsgId`)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- 主键<br style="font-family: " />
)DEFAULT CHARSET=gb2312;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- 设置表的字符集<br style="font-family: " />
<br style="font-family: " />
-- 建立索引<br style="font-family: " />
<br style="font-family: " />
create unique index BCG_Msg_idx2 on Msg ( MsgTypeId,&nbsp; MsgId );<br style="font-family: " />
<br style="font-family: " />
-- 建立存储过程<br style="font-family: " />
<br style="font-family: " />
<span style="font-family: ; color: #ff1493">DELIMITER |&nbsp; --必须有此句</span></p>
<p style="font-family: ">CREATE PROCEDURE BCG_QueueMsg<br style="font-family: " />
&nbsp;&nbsp; (<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp; in v_MsgServiceName varchar(30),<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp; in v_MsgParam1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; varchar(60)<br style="font-family: " />
&nbsp;&nbsp; )<br style="font-family: " />
BEGIN<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DECLARE v_MsgTypeId integer;<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DECLARE v_QueuedAt&nbsp; timestamp;<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set v_QueuedAt = now();<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT MsgServiceId INTO v_MsgServiceId FROM BCG_MsgService where MsgServiceName=v_MsgServiceName;<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INSERT INTO Msg (<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgTypeId, <br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgQueuedAt,&nbsp;<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgParam1<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALUES (<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v_MsgTypeId,<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v_QueuedAt,&nbsp;<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v_MsgParam1<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<br style="font-family: " />
END;<br style="font-family: " />
<span style="font-family: ; color: #ff1493">|<br style="font-family: " />
DELIMITER ;</span><br style="font-family: " />
<br style="font-family: " />
3、触发器的建立<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp;a、选择File-〉New Script Tab<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp;b、在Script 2的Tab页中输入以下语句，选择Execute按钮执行即可。<br style="font-family: " />
<br style="font-family: " />
-- 使用sample数据库<br style="font-family: " />
use sample;<br style="font-family: " />
<br style="font-family: " />
-- 建立测试表<br style="font-family: " />
<br style="font-family: " />
CREATE TABLE Orders (<br style="font-family: " />
&nbsp;OrderID int NOT NULL auto_increment ,<br style="font-family: " />
&nbsp;CustomerID nchar (5)&nbsp; NULL ,<br style="font-family: " />
&nbsp;EmployeeID int NULL ,<br style="font-family: " />
&nbsp;OrderDate datetime NULL ,<br style="font-family: " />
&nbsp;RequiredDate datetime NULL ,<br style="font-family: " />
&nbsp;ShippedDate datetime NULL ,<br style="font-family: " />
&nbsp;ShipVia int NULL ,<br style="font-family: " />
&nbsp;Freight float NULL ,<br style="font-family: " />
&nbsp;ShipName nvarchar (40) NULL ,<br style="font-family: " />
&nbsp;ShipAddress nvarchar (60)&nbsp; NULL ,<br style="font-family: " />
&nbsp;ShipCity nvarchar (15)&nbsp; NULL ,<br style="font-family: " />
&nbsp;ShipRegion nvarchar (15)&nbsp; NULL ,<br style="font-family: " />
&nbsp;ShipPostalCode nvarchar (10)&nbsp;&nbsp; NULL ,<br style="font-family: " />
&nbsp;ShipCountry nvarchar (15)&nbsp;&nbsp; NULL,<br style="font-family: " />
&nbsp; PRIMARY KEY&nbsp; (`OrderID`)<br style="font-family: " />
)DEFAULT CHARSET = gb2312;<br style="font-family: " />
<br style="font-family: " />
-- 建立触发器 TESTDBINSERT&nbsp; ，当有记录插入表时，同时插入Msg表一条记录<br style="font-family: " />
<br style="font-family: " />
DELIMITER |<br style="font-family: " />
CREATE TRIGGER TESTDBINSERT&nbsp; AFTER&nbsp; INSERT ON ORDERS<br style="font-family: " />
FOR EACH ROW<br style="font-family: " />
BEGIN<br style="font-family: " />
&nbsp;&nbsp;&nbsp; -- 把新插入orders表中新记录的OrderID字段的值赋给ID，<span style="font-family: ; color: #ff1493">NEW表示当前插入的记录项内容<br style="font-family: " />
</span>&nbsp;&nbsp;&nbsp; SET @ID = <span style="font-family: ; color: #ff1493">NEW</span>.OrderID;&nbsp; </p>
<p style="font-family: ">&nbsp;&nbsp;&nbsp; -- 获得当前时间<br style="font-family: " />
&nbsp;&nbsp;&nbsp; SET @v_QueuedAt = NOW();<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp; -- 把以上得到的值插入Msg表中<br style="font-family: " />
&nbsp;&nbsp;&nbsp; INSERT INTO Msg (<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgTypeId,<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgQueuedAt,&nbsp;<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgParam1<br style="font-family: " />
&nbsp;&nbsp;&nbsp; ) VALUES (<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1,<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @v_QueuedAt,&nbsp;<br style="font-family: " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @ID<br style="font-family: " />
&nbsp;&nbsp;&nbsp; );<br style="font-family: " />
END;<br style="font-family: " />
|<br style="font-family: " />
DELIMITER ;<br style="font-family: " />
<br style="font-family: " />
&nbsp;&nbsp;&nbsp;c、这时在表orders中插入一条记录，则Msg表中也增加一条记录。<br style="font-family: " />
<br style="font-family: " />
最后说明MySQL GUI Tools 5.0是一个十分好用的工具，还有可以从其他数据库中导入数据的GUI工具，希望大家多多研究。</p>
</span>
<img src ="http://www.blogjava.net/JeromeKwok/aggbug/311987.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/JeromeKwok/" target="_blank">Jerome Kwok</a> 2010-02-04 15:53 <a href="http://www.blogjava.net/JeromeKwok/articles/311987.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MySql数据库备份mysqldump参数选项</title><link>http://www.blogjava.net/JeromeKwok/articles/311988.html</link><dc:creator>Jerome Kwok</dc:creator><author>Jerome Kwok</author><pubDate>Thu, 04 Feb 2010 07:53:00 GMT</pubDate><guid>http://www.blogjava.net/JeromeKwok/articles/311988.html</guid><wfw:comment>http://www.blogjava.net/JeromeKwok/comments/311988.html</wfw:comment><comments>http://www.blogjava.net/JeromeKwok/articles/311988.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/JeromeKwok/comments/commentRss/311988.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/JeromeKwok/services/trackbacks/311988.html</trackback:ping><description><![CDATA[<p><span style="font-family: Courier; font-size: 10pt"><a style="font-family: ">实用程序，为备份或为把数据转移到另外的SQL服务器上倾倒一个数据库或许多数据库。倾倒将包含&nbsp;创建表或充实表的SQL语句。&nbsp;<br style="font-family: " />
<br style="font-family: " />
shell&gt;&nbsp;mysqldump&nbsp;[OPTIONS]&nbsp;database&nbsp;[tables]<br style="font-family: " />
<br style="font-family: " />
如果你不给定任何表，整个数据库将被倾倒。&nbsp;<br style="font-family: " />
<br style="font-family: " />
通过执行mysqldump&nbsp;--help，你能得到你mysqldump的版本支持的选项表。&nbsp;<br style="font-family: " />
<br style="font-family: " />
注意，如果你运行mysqldump没有--quick或--opt选项，mysqldump将在倾倒结果前装载整个结果集到内存中，如果你正在倾倒一个大的数据库，这将可能是一个问题。&nbsp;<br style="font-family: " />
<br style="font-family: " />
mysqldump支持下列选项：&nbsp;<br style="font-family: " />
<br style="font-family: " />
--add-locks&nbsp;<br style="font-family: " />
在每个表倾倒之前增加LOCK&nbsp;TABLES并且之后UNLOCK&nbsp;TABLE。(为了使得更快地插入到MySQL)。&nbsp;<br style="font-family: " />
--add-drop-table&nbsp;<br style="font-family: " />
在每个create语句之前增加一个drop&nbsp;table。&nbsp;<br style="font-family: " />
--allow-keywords&nbsp;<br style="font-family: " />
允许创建是关键词的列名字。这由表名前缀于每个列名做到。&nbsp;<br style="font-family: " />
-c,&nbsp;--complete-insert&nbsp;<br style="font-family: " />
使用完整的insert语句(用列名字)。&nbsp;<br style="font-family: " />
-C,&nbsp;--compress&nbsp;<br style="font-family: " />
如果客户和服务器均支持压缩，压缩两者间所有的信息。&nbsp;<br style="font-family: " />
--delayed&nbsp;<br style="font-family: " />
用INSERT&nbsp;DELAYED命令插入行。&nbsp;<br style="font-family: " />
-e,&nbsp;--extended-insert&nbsp;<br style="font-family: " />
使用全新多行INSERT语法。（给出更紧缩并且更快的插入语句）&nbsp;<br style="font-family: " />
-#,&nbsp;--debug[=option_string]&nbsp;<br style="font-family: " />
跟踪程序的使用(为了调试)。&nbsp;<br style="font-family: " />
--help&nbsp;<br style="font-family: " />
显示一条帮助消息并且退出。&nbsp;<br style="font-family: " />
--fields-terminated-by=...&nbsp;<br style="font-family: " />
　&nbsp;<br style="font-family: " />
--fields-enclosed-by=...&nbsp;<br style="font-family: " />
　&nbsp;<br style="font-family: " />
--fields-optionally-enclosed-by=...&nbsp;<br style="font-family: " />
　&nbsp;<br style="font-family: " />
--fields-escaped-by=...&nbsp;<br style="font-family: " />
　&nbsp;<br style="font-family: " />
--fields-terminated-by=...&nbsp;<br style="font-family: " />
这些选择与-T选择一起使用，并且有相应的LOAD&nbsp;DATA&nbsp;INFILE子句相同的含义。见7.16&nbsp;LOAD&nbsp;DATA&nbsp;INFILE语法。&nbsp;<br style="font-family: " />
-F,&nbsp;--flush-logs&nbsp;<br style="font-family: " />
在开始倾倒前，洗掉在MySQL服务器中的日志文件。&nbsp;<br style="font-family: " />
-f,&nbsp;--force,&nbsp;<br style="font-family: " />
即使我们在一个表倾倒期间得到一个SQL错误，继续。&nbsp;<br style="font-family: " />
-h,&nbsp;--host=..&nbsp;<br style="font-family: " />
从命名的主机上的MySQL服务器倾倒数据。缺省主机是localhost。&nbsp;<br style="font-family: " />
-l,&nbsp;--lock-tables.&nbsp;<br style="font-family: " />
为开始倾倒锁定所有表。&nbsp;<br style="font-family: " />
-t,&nbsp;--no-create-info&nbsp;<br style="font-family: " />
不写入表创建信息(CREATE&nbsp;TABLE语句）&nbsp;<br style="font-family: " />
-d,&nbsp;--no-data&nbsp;<br style="font-family: " />
不写入表的任何行信息。如果你只想得到一个表的结构的倾倒，这是很有用的！&nbsp;<br style="font-family: " />
--opt&nbsp;<br style="font-family: " />
同--quick&nbsp;--add-drop-table&nbsp;--add-locks&nbsp;--extended-insert&nbsp;--lock-tables。应该给你为读入一个MySQL服务器的尽可能最快的倾倒。&nbsp;<br style="font-family: " />
-pyour_pass,&nbsp;--password[=your_pass]&nbsp;<br style="font-family: " />
与服务器连接时使用的口令。如果你不指定&#8220;=your_pass&#8221;部分，mysqldump需要来自终端的口令。&nbsp;<br style="font-family: " />
-P&nbsp;port_num,&nbsp;--port=port_num&nbsp;<br style="font-family: " />
与一台主机连接时使用的TCP/IP端口号。（这用于连接到localhost以外的主机，因为它使用&nbsp;Unix套接字。）&nbsp;<br style="font-family: " />
-q,&nbsp;--quick&nbsp;<br style="font-family: " />
不缓冲查询，直接倾倒至stdout；使用mysql_use_result()做它。&nbsp;<br style="font-family: " />
-S&nbsp;/path/to/socket,&nbsp;--socket=/path/to/socket&nbsp;<br style="font-family: " />
与localhost连接时（它是缺省主机)使用的套接字文件。&nbsp;<br style="font-family: " />
-T,&nbsp;--tab=path-to-some-directory&nbsp;<br style="font-family: " />
对于每个给定的表，创建一个table_name.sql文件，它包含SQL&nbsp;CREATE&nbsp;命令，和一个table_name.txt文件，它包含数据。&nbsp;注意：这只有在mysqldump运行在mysqld守护进程运行的同一台机器上的时候才工作。.txt文件的格式根据--fields-xxx和 --lines--xxx选项来定。&nbsp;<br style="font-family: " />
-u&nbsp;user_name,&nbsp;--user=user_name&nbsp;<br style="font-family: " />
与服务器连接时，MySQL使用的用户名。缺省值是你的Unix登录名。&nbsp;<br style="font-family: " />
-O&nbsp;var=option,&nbsp;--set-variable&nbsp;var=option&nbsp;<br style="font-family: " />
设置一个变量的值。可能的变量被列在下面。&nbsp;<br style="font-family: " />
-v,&nbsp;--verbose&nbsp;<br style="font-family: " />
冗长模式。打印出程序所做的更多的信息。&nbsp;<br style="font-family: " />
-V,&nbsp;--version&nbsp;<br style="font-family: " />
打印版本信息并且退出。&nbsp;<br style="font-family: " />
-w,&nbsp;--where='where-condition'&nbsp;<br style="font-family: " />
只倾倒被选择了的记录；注意引号是强制的！&nbsp;<br style="font-family: " />
"--where=user='jimf'"&nbsp;"-wuserid&gt;1"&nbsp;"-wuserid&lt;1"<br style="font-family: " />
<br style="font-family: " />
最常见的mysqldump使用可能制作整个数据库的一个备份：&nbsp;<br style="font-family: " />
<br style="font-family: " />
mysqldump&nbsp;--opt&nbsp;database&nbsp;&gt;&nbsp;backup-file.sql&nbsp;<br style="font-family: " />
<br style="font-family: " />
但是它对用来自于一个数据库的信息充实另外一个MySQL数据库也是有用的：&nbsp;<br style="font-family: " />
<br style="font-family: " />
mysqldump&nbsp;--opt&nbsp;database&nbsp;│&nbsp;mysql&nbsp;--host=remote-host&nbsp;-C&nbsp;database</a><a>&nbsp;</p>
</span></a>
<img src ="http://www.blogjava.net/JeromeKwok/aggbug/311988.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/JeromeKwok/" target="_blank">Jerome Kwok</a> 2010-02-04 15:53 <a href="http://www.blogjava.net/JeromeKwok/articles/311988.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql中文乱码问题</title><link>http://www.blogjava.net/JeromeKwok/articles/284382.html</link><dc:creator>Jerome Kwok</dc:creator><author>Jerome Kwok</author><pubDate>Sat, 27 Jun 2009 04:04:00 GMT</pubDate><guid>http://www.blogjava.net/JeromeKwok/articles/284382.html</guid><wfw:comment>http://www.blogjava.net/JeromeKwok/comments/284382.html</wfw:comment><comments>http://www.blogjava.net/JeromeKwok/articles/284382.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/JeromeKwok/comments/commentRss/284382.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/JeromeKwok/services/trackbacks/284382.html</trackback:ping><description><![CDATA[<span style="font-size: 10pt; font-family: Courier">首先我们先在mysql命令行下输入<br style="font-family: " />
show variables like '%char%';<br style="font-family: " />
查看mysql字符集设置情况<br style="font-family: " />
<img style="font-family: " height="229" alt="" src="http://www.blogjava.net/images/blogjava_net/jeromekwok/mysql.JPG" width="580" border="0" /><br style="font-family: " />
问题主要出在5个环节<br style="font-family: " />
1.数据库启动字符集<br style="font-family: " />
2.数据库存储字符集<br style="font-family: " />
3.数据库连接传输字符集<br style="font-family: " />
4.数据库客户端字符集<br style="font-family: " />
5.数据库查询结果字符集<br style="font-family: " />
<br style="font-family: " />
乱码的情况：<br style="font-family: " />
1.插入数据库时作为乱码插入<br style="font-family: " />
2.查询结果以乱码显示<br style="font-family: " />
<br style="font-family: " />
解决方法<br style="font-family: " />
1.mysql安装时确定，也可以更改配置文件<br style="font-family: " />
2.建数据库语句后加上default character set 字符集（GBK或utf8等，注意大小写）<br style="font-family: " />
3.JDBC设置URL时这么写：URL=jdbc:mysql://localhost:3306/abs?useUnicode=true&amp;characterEncoding=字符集<br style="font-family: " />
4.5.mysql命令行下输入 set names 字符集<br style="font-family: " />
作用相当于<br style="font-family: " />
set character_set_client = 字符集<br style="font-family: " />
set character_set_connection = 字符集<br style="font-family: " />
set character_set_results = 字符集<br style="font-family: " />
<br style="font-family: " />
</span>
  <img src ="http://www.blogjava.net/JeromeKwok/aggbug/284382.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/JeromeKwok/" target="_blank">Jerome Kwok</a> 2009-06-27 12:04 <a href="http://www.blogjava.net/JeromeKwok/articles/284382.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>