﻿<?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>C++博客-&lt;font color="#ff8000"&gt;&amp;nbsp&amp;nbsp&amp;nbspC++&amp;nbsp技术中心&lt;/font&gt;-随笔分类-MYSQL</title><link>http://www.cppblog.com/API/category/16119.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 24 Jan 2016 03:15:13 GMT</lastBuildDate><pubDate>Sun, 24 Jan 2016 03:15:13 GMT</pubDate><ttl>60</ttl><item><title>安装mysql5.7.10</title><link>http://www.cppblog.com/API/archive/2016/01/21/212705.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Thu, 21 Jan 2016 08:15:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2016/01/21/212705.html</guid><wfw:comment>http://www.cppblog.com/API/comments/212705.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2016/01/21/212705.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/212705.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/212705.html</trackback:ping><description><![CDATA[<span style="font-size: 12pt;">1.去官网下载http://dev.mysql.com/downloads/mysql/选其中的</span><strong style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12pt; vertical-align: baseline; color: #555555; font-family: 'Open Sans', Arial, Helvetica, sans-serif; line-height: 20.7360000610352px; background: #fcfdfd;">Windows (x86, 64-bit), ZIP Archive或<strong style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12.960000038147px; vertical-align: baseline; line-height: 20.7360000610352px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">Windows (x86, 32-bit), ZIP Archive版本<br /></strong>2.<span style="color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; font-weight: normal; line-height: 28px; text-align: justify; background-color: #ffffff;">在mysql-5.7.10-winx64目录下，新建一个my.ini。复制下面的代码保存就可以了。</span></strong><strong style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12.960000038147px; vertical-align: baseline; color: #555555; font-family: 'Open Sans', Arial, Helvetica, sans-serif; line-height: 20.7360000610352px; background: #fcfdfd;"><span style="color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; font-weight: normal; line-height: 28px; text-align: justify; background-color: #ffffff;"><br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #800000;">[</span><span style="color: #800000; ">mysql</span><span style="color: #800000;">]</span><span style="color: #000000; "><br /></span><span style="color: #008000; ">;</span><span style="color: #008000; ">&nbsp;设置mysql客户端默认字符集</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">default-character-set</span><span style="color: #000000; ">=</span><span style="color: #000000; ">utf8<br /></span><span style="color: #800000;">[</span><span style="color: #800000; ">mysqld</span><span style="color: #800000;">]</span><span style="color: #000000; "><br /></span><span style="color: #008000; ">;</span><span style="color: #008000; ">设置3306端口</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">port&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">3306</span><span style="color: #000000; ">&nbsp;<br /></span><span style="color: #008000; ">;</span><span style="color: #008000; ">&nbsp;设置mysql的安装目录</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">basedir</span><span style="color: #000000; ">=D:\MYSQL\mysql-5.7.10-winx64</span><span style="color: #000000; "><br /></span><span style="color: #008000; ">;</span><span style="color: #008000; ">&nbsp;设置mysql数据库的数据的存放目录</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">datadir</span><span style="color: #000000; ">=D:\MYSQL\mysql-5.7.10-winx64\data</span><span style="color: #000000; "><br /></span><span style="color: #008000; ">;</span><span style="color: #008000; ">&nbsp;允许最大连接数</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">max_connections</span><span style="color: #000000; ">=</span><span style="color: #000000; ">200</span><span style="color: #000000; "><br /></span><span style="color: #008000; ">;</span><span style="color: #008000; ">&nbsp;服务端使用的字符集默认为8比特编码的latin1字符集</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">character-set-server</span><span style="color: #000000; ">=</span><span style="color: #000000; ">utf8<br /></span><span style="color: #008000; ">;</span><span style="color: #008000; ">&nbsp;创建新表时将使用的默认存储引擎</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">default-storage-engine</span><span style="color: #000000; ">=</span><span style="color: #000000; ">MYISAM</span></div></strong><span style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12pt; vertical-align: baseline; line-height: 20.7360000610352px; background: #f3f3f3;">3.在win下以管理员身份运行cmd<br /></span><span style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12pt; vertical-align: baseline; line-height: 20.7360000610352px; background: #f3f3f3;">4.在bin目录下，运行&gt;mysqld install<br /></span><span style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12pt; vertical-align: baseline; line-height: 20.7360000610352px; background: #f3f3f3;">5.然后运行&gt;</span><span style="color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 12pt; line-height: 28px; text-align: justify; background-color: #ffffff;">mysqld&nbsp;&nbsp;--initialize<br /></span><span style="color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 12pt; line-height: 28px; text-align: justify; background-color: #ffffff;">&nbsp; 这个初始化操作将my.ini中的datadir目录下生成数据库文件，也可以将该里面的文件全删除。重新输入该命令初始化<br /></span><span style="color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 12pt; line-height: 28px; text-align: justify; background-color: #ffffff;">6.启动服务&gt;net start mysql<br /></span><span style="color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 12pt; line-height: 28px; text-align: justify; background-color: #ffffff;">7. 修改密码<br /></span><p style="margin: 0px; padding: 0px; color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; line-height: 28px; text-align: justify; background-color: #ffffff;"><span style="font-size: 12pt;">打开MySQL/bin目录下输入mysql -uroot -p ,默认是没有密码的，一般是直接按回车进入，但是会出现</span><br /><span style="font-size: 12pt;">ERROR 1045 (28000): Access denied for user'root'@'localhost'(using password: YES)的错误 。</span><br /><span style="font-size: 12pt;">解决的方法都是在在配置文件[mysqld]条目下加一条命令skip-grant-tables然后重启服务就可以略过密码进入了。</span></p><p style="margin: 0px; padding: 0px; color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; line-height: 28px; text-align: justify; background-color: #ffffff;"><span style="font-size: 12pt;">在cmd里面输入mysql -u root-p就可以不用密码登录了，出现password：的时候直接回车可以进入，不会出现ERROR 1045(28000)，但很多操作都会受限制，因为没有不能grant（没有权限）的密码</span></p><p style="margin: 0px; padding: 0px; color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; line-height: 28px; text-align: justify; background-color: #ffffff;"><span style="font-size: 12pt;">(1).进入mysql数据库：</span></p><p style="margin: 0px; padding: 0px; color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; line-height: 28px; text-align: justify; background-color: #ffffff;"><span style="font-size: 12pt;">mysql&gt; use mysql;Database changed</span></p><p style="margin: 0px; padding: 0px; color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; line-height: 28px; text-align: justify; background-color: #ffffff;"><span style="font-size: 12pt;">(2).给root用户设置新密码mysql&gt; update user set authentication_string=password("123456") where user="root"; </span><br /><span style="font-size: 12pt;">&nbsp;Query OK,1 rows affected(0.01 sec)Rows matched:1 Changed:1Warnings: 0</span><br /></p><p style="margin: 0px; padding: 0px; color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; line-height: 28px; text-align: justify; background-color: #ffffff;"><span style="font-size: 12pt;">(3).刷新数据库&nbsp;（一定要记得刷新）mysql&gt;flush privileges;&nbsp;QueryOK, 0 rows affected (0.00 sec)</span></p><p style="margin: 0px; padding: 0px; color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; line-height: 28px; text-align: justify; background-color: #ffffff;"><span style="font-size: 12pt;">(4).退出mysql：mysql&gt; quit</span></p><span style="color: #333333; font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 12pt; line-height: 28px; text-align: justify; background-color: #ffffff;">最后把配置文件中的skip-grant-tables 注释掉。下次输入mysql&nbsp;-uroot -p 就可以用新密码登录了</span><br /><span style="text-align: justify; background-color: #ffffff;"><font color="#333333" face="Microsoft Yahei, 微软雅黑, arial, 宋体, sans-serif"><span style="font-size: 16px; line-height: 28px;">8.如果再次进入输入 &gt;show databases;提示以下错误:</span></font><br /></span><div><span style="font-size: 16px; line-height: 28px;">ERROR 1820 (HY000): You must reset your password using ALTER USER statement befo</span><span style="font-size: 16px; line-height: 28px;">re executing this statement.<br /></span></div><span style="text-align: justify; background-color: #ffffff;">则修改一次密码即可:&gt;</span>set password=password('123456');<span style="text-align: justify; background-color: #ffffff;"><br /></span><span style="text-align: justify; background-color: #ffffff;"><br /><br /><br /><br /></span><img src ="http://www.cppblog.com/API/aggbug/212705.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2016-01-21 16:15 <a href="http://www.cppblog.com/API/archive/2016/01/21/212705.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql 保留N行的重复记录</title><link>http://www.cppblog.com/API/archive/2014/03/26/206349.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Wed, 26 Mar 2014 07:16:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2014/03/26/206349.html</guid><wfw:comment>http://www.cppblog.com/API/comments/206349.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2014/03/26/206349.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/206349.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/206349.html</trackback:ping><description><![CDATA[1.原表<br /><div>mysql&gt; select * from t_value;</div><div>+----+------------+</div><div>| id | value &nbsp; &nbsp; &nbsp;|</div><div>+----+------------+</div><div>| &nbsp;1 | &nbsp; &nbsp; &nbsp; 1212 |</div><div>| &nbsp;1 | &nbsp; &nbsp;1234342 |</div><div>| &nbsp;1 | &nbsp; &nbsp; &nbsp; &nbsp; 12 |</div><div>| &nbsp;1 | 1243242341 |</div><div>| &nbsp;2 | &nbsp; 43242341 |</div><div>| &nbsp;2 | &nbsp; &nbsp; &nbsp;43241 |</div><div>| &nbsp;2 | &nbsp; &nbsp;4333331 |</div><div>| &nbsp;2 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4 |</div><div>| &nbsp;2 | &nbsp;432456666 |</div><div>+----+------------+</div><div>9 rows in set<br />2. 期望以上id为1，2的分别只保留两条<br />3.新建一个临时表，字段同上，并新增一个num字段为自增。并插入<br />insert into t_tmp(id,value) select id,value from t_value order by id;<br />4.于是t_tmp如下：<br /><div>mysql&gt; select * from t_tmp;</div><div>+----+------------+-----+</div><div>| id | value &nbsp; &nbsp; &nbsp;| num |</div><div>+----+------------+-----+</div><div>| &nbsp;1 | &nbsp; &nbsp; &nbsp; 1212 | &nbsp;79 |</div><div>| &nbsp;1 | &nbsp; &nbsp;1234342 | &nbsp;80 |</div><div>| &nbsp;1 | &nbsp; &nbsp; &nbsp; &nbsp; 12 | &nbsp;81 |</div><div>| &nbsp;1 | 1243242341 | &nbsp;82 |</div><div>| &nbsp;2 | &nbsp; 43242341 | &nbsp;83 |</div><div>| &nbsp;2 | &nbsp; &nbsp; &nbsp;43241 | &nbsp;84 |</div><div>| &nbsp;2 | &nbsp; &nbsp;4333331 | &nbsp;85 |</div><div>| &nbsp;2 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4 | &nbsp;86 |</div><div>| &nbsp;2 | &nbsp;432456666 | &nbsp;87 |</div><div>+----+------------+-----+<br /><br />5.再通过以下SQL查出<br /><div>mysql&gt; select t_tmp.id,t_tmp.value,t_tmp.num from t_tmp</div><div>left join(select num,id,value from t_tmp &nbsp; group by id) as t</div><div>on t.id=t_tmp.id</div><div>where t_tmp.num&lt;t.num+2;</div><div>+----+----------+-----+</div><div>| id | value &nbsp; &nbsp;| num |</div><div>+----+----------+-----+</div><div>| &nbsp;1 | &nbsp; &nbsp; 1212 | &nbsp;79 |</div><div>| &nbsp;1 | &nbsp;1234342 | &nbsp;80 |</div><div>| &nbsp;2 | 43242341 | &nbsp;83 |</div><div>| &nbsp;2 | &nbsp; &nbsp;43241 | &nbsp;84 |</div><div>+----+----------+-----+</div></div></div><img src ="http://www.cppblog.com/API/aggbug/206349.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2014-03-26 15:16 <a href="http://www.cppblog.com/API/archive/2014/03/26/206349.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql系统表proc</title><link>http://www.cppblog.com/API/archive/2013/03/09/198319.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Sat, 09 Mar 2013 09:43:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2013/03/09/198319.html</guid><wfw:comment>http://www.cppblog.com/API/comments/198319.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2013/03/09/198319.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/198319.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/198319.html</trackback:ping><description><![CDATA[<div>1.在系统表proc中的definer字段用来管理存储过程的访问权限</div><img src ="http://www.cppblog.com/API/aggbug/198319.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2013-03-09 17:43 <a href="http://www.cppblog.com/API/archive/2013/03/09/198319.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql导出表结构与存储过程</title><link>http://www.cppblog.com/API/archive/2013/03/09/198318.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Sat, 09 Mar 2013 09:33:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2013/03/09/198318.html</guid><wfw:comment>http://www.cppblog.com/API/comments/198318.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2013/03/09/198318.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/198318.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/198318.html</trackback:ping><description><![CDATA[<div>my<font size="3" face="Times New Roman">sqldump.exe -uroot -p123456 -d -R slot &gt; slot.sql</font></div><img src ="http://www.cppblog.com/API/aggbug/198318.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2013-03-09 17:33 <a href="http://www.cppblog.com/API/archive/2013/03/09/198318.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> MySQL数字的进制转换</title><link>http://www.cppblog.com/API/archive/2013/01/14/197265.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Mon, 14 Jan 2013 09:45:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2013/01/14/197265.html</guid><wfw:comment>http://www.cppblog.com/API/comments/197265.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2013/01/14/197265.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/197265.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/197265.html</trackback:ping><description><![CDATA[<p align="left">&nbsp;MySQL数字的进制转换(conv的使用)<br />CONV(N,from_base,to_base)<br />在不同的数字基数之间转换数字。将数字 N 从from_base 转换到 to_base，并以字符串形式返回。如果任何一个参数为 NULL，那么返回值也为 NULL。参数 N 被解释为是一个整数，但是也可以被指定为一个整数或一个字符串。最小基为 2，最大基为 36。如果 to_base 是一个负值，N 将被看作为是一个有符号数字。否则，N 被视为是无符号的。CONV 以 64 位精度工作。<br /><br /><a class="keylink" href="http://www.2cto.com/database/mysql/" target="_blank">mysql</a>&gt; select conv(100,10,2);<br />+----------------+<br />| conv(100,10,2) |<br />+----------------+<br />| 1100100 |<br />+----------------+</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">insert</span><span style="color: #000000">&nbsp;ignore&nbsp;</span><span style="color: #0000ff">into</span><span style="color: #000000">&nbsp;tbl_Device_User_Info_1&nbsp;&nbsp;(deviceKey,iggid,userid,DriveType,LastLoginTime,Param1,DeviceID)&nbsp;</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;deviceKey,iggid,userid,DriveType,LastLoginTime,Param1,DeviceID&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;tbl_Device_User_Info_Mix&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;conv(</span><span style="color: #ff00ff">right</span><span style="color: #000000">(deviceKey,</span><span style="color: #800000; font-weight: bold">4</span><span style="color: #000000">),</span><span style="color: #800000; font-weight: bold">16</span><span style="color: #000000">,</span><span style="color: #800000; font-weight: bold">10</span><span style="color: #000000">)&nbsp;mod&nbsp;</span><span style="color: #800000; font-weight: bold">40</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">+</span><span style="color: #800000; font-weight: bold">1</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000; font-weight: bold">1</span><span style="color: #000000">&nbsp;;</span></div>
<p align="left"><br /><br /></p><img src ="http://www.cppblog.com/API/aggbug/197265.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2013-01-14 17:45 <a href="http://www.cppblog.com/API/archive/2013/01/14/197265.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MySql中插入中文报错：incorrect string value </title><link>http://www.cppblog.com/API/archive/2012/10/15/193304.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Mon, 15 Oct 2012 05:14:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/10/15/193304.html</guid><wfw:comment>http://www.cppblog.com/API/comments/193304.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/10/15/193304.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/193304.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/193304.html</trackback:ping><description><![CDATA[<p style="line-height: normal">&nbsp;SHOW VARIABLES LIKE 'character_set_%';<br /><br />最近向ＭｙＳＱＬ数据库插入数据时出现了一个问题，报告中文错误：incorrect string value<span style="line-height: normal; color: rgb(102,102,102)"><span> </span>．．．．．在网上搜了一些资料也都是宽泛的说说，自己综合各家之长，试了试，发现把数据库编码、页面编码和Ｊａｖａ文件编码修改成统一的编码方案就行了。</span></p>
<p style="line-height: normal"><span style="line-height: normal; color: rgb(102,102,102)">　在ＭｙＳＱＬ命令窗口下输入＼ｓ就可以查看当前数据库的编码了。</span></p>
<p style="line-height: normal"><span style="line-height: normal; color: rgb(102,102,102)">　<strong style="line-height: normal">修改方法</strong></span></p>
<p style="line-height: normal"><span style="line-height: normal; color: rgb(102,102,102)">页面和Java文件中的修改就不说了，大家肯定都会，只说说怎样修改MySQL的吧。</span></p>
<p style="line-height: normal"><span style="line-height: normal; color: rgb(102,102,102)">修改数据库编码的命令是：ALTER DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin</span></p>
<p style="line-height: normal"><span style="line-height: normal; color: rgb(102,102,102)">　修改表的编码的命令是：ALTER TABLE `category` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin</span></p>
<p style="line-height: normal"><span style="line-height: normal; color: rgb(102,102,102)">　修改表中字段的编码的命令是：ALTER TABLE `test` CHANGE `dd` `dd` VARCHAR( 45 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL</span></p>
<p style="line-height: normal"><span style="line-height: normal; color: rgb(102,102,102)">修改MySQL默认编码方案，在<strong style="line-height: normal">windows环境下</strong>可以直接用Mysql Server Instance Config Wizard 进行设置</span></p>
<p style="line-height: normal"><span style="line-height: normal; color: rgb(102,102,102)"><strong style="line-height: normal">Linux环境下</strong></span></p>
<p style="line-height: normal"><span style="line-height: normal; color: rgb(102,102,102)">/etc/init.d/mysql start (stop) 为启动和停止服务器</span></p>
<p style="line-height: normal">　　/etc/mysql/ 主要配置文件所在位置 my.cnf</p>
<p style="line-height: normal">　　/var/lib/mysql/ 放置的是数据库表文件夹，这里的mysql相当于windows下mysql的date文件夹</p>
<p style="line-height: normal">　　启动mysql后，以root登录mysql</p>
<p style="line-height: normal">　　isher@isher-ubuntu:~$ mysql -u root</p>
<p style="line-height: normal">　　&gt;show variables like 'character%'; #执行编码显示</p>
<p style="line-height: normal">　　+--------------------------+----------------------------+</p>
<p style="line-height: normal">　　| Variable_name | Value |</p>
<p style="line-height: normal">　　+--------------------------+----------------------------+</p>
<p style="line-height: normal">　　| character_set_client | latin1 |</p>
<p style="line-height: normal">　　| character_set_connection | latin1 |</p>
<p style="line-height: normal">　　| character_set_database | latin1 |</p>
<p style="line-height: normal">　　| character_set_filesystem | binary |</p>
<p style="line-height: normal">　　| character_set_results | latin1 |</p>
<p style="line-height: normal">　　| character_set_server | latin1 |</p>
<p style="line-height: normal">　　| character_set_system | utf8 |</p>
<p style="line-height: normal">　　| character_sets_dir | /usr/share/mysql/charsets/ |</p>
<p style="line-height: normal">　　+--------------------------+----------------------------+</p>
<p style="line-height: normal">　　在某些时候，我们续要修改mysql默认数据库的编码，以保证某些迁移的程序可以正常显示，编辑my.cnf文件进行编码修改,windows可以直接用Mysql Server Instance Config Wizard 进行设置</p>
<p style="line-height: normal">　　在linux下修改3个my.cnf的1个/etc/mysql/my.cnf文件</p>
<p style="line-height: normal">　　找到客户端配置[client] 在下面添加</p>
<p style="line-height: normal">　　default-character-set=utf8 默认字符集为utf8</p>
<p style="line-height: normal">　　在找到[mysqld] 添加</p>
<p style="line-height: normal">　　default-character-set=utf8 默认字符集为utf8</p>
<p style="line-height: normal">　　init_connect='SET NAMES utf8' (设定连接mysql数据库时使用utf8编码，以让mysql数据库为utf8运行)</p>
<p style="line-height: normal">　　修改好后，重新启动mysql 即可，查询一下show variables like 'character%';</p>
<p style="line-height: normal">　　+--------------------------+----------------------------+</p>
<p style="line-height: normal">　　| Variable_name | Value |</p>
<p style="line-height: normal">　　+--------------------------+----------------------------+</p>
<p style="line-height: normal">　　| character_set_client | utf8 |</p>
<p style="line-height: normal">　　| character_set_connection | utf8 |</p>
<p style="line-height: normal">　　| character_set_database | utf8 |</p>
<p style="line-height: normal">　　| character_set_filesystem | binary |</p>
<p style="line-height: normal">　　| character_set_results | utf8 |</p>
<p style="line-height: normal">　　| character_set_server | utf8 |</p>
<p style="line-height: normal">　　| character_set_system | utf8 |</p>
<p style="line-height: normal">　　| character_sets_dir | /usr/share/mysql/charsets/ |</p>
<p style="line-height: normal">　　+--------------------------+----------------------------+</p>
<p style="line-height: normal">　　此方法用于标准mysql版本同样有效，对于/etc/my.cnf文件，需要从mysql/support-files的文件夹cp my-large.cnf一份到/etc/my.cnf。</p><img src ="http://www.cppblog.com/API/aggbug/193304.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-10-15 13:14 <a href="http://www.cppblog.com/API/archive/2012/10/15/193304.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>批量修改表引擎</title><link>http://www.cppblog.com/API/archive/2012/09/12/190421.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Wed, 12 Sep 2012 10:06:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/09/12/190421.html</guid><wfw:comment>http://www.cppblog.com/API/comments/190421.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/09/12/190421.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/190421.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/190421.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">drop</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">procedure</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">exists</span><span style="color: #000000">&nbsp;sp_TableEng;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">create</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">procedure</span><span style="color: #000000">&nbsp;&nbsp;sp_TableEng(dbname&nbsp;</span><span style="color: #000000; font-weight: bold">varchar</span><span style="color: #000000">(</span><span style="color: #800000; font-weight: bold">50</span><span style="color: #000000">))<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">BEGIN</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">DECLARE</span><span style="color: #000000">&nbsp;done&nbsp;</span><span style="color: #000000; font-weight: bold">INT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">DEFAULT</span><span style="color: #000000">&nbsp;</span><span style="color: #800000; font-weight: bold">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">DECLARE</span><span style="color: #000000">&nbsp;v_tbname&nbsp;</span><span style="color: #000000; font-weight: bold">varchar</span><span style="color: #000000">(</span><span style="color: #800000; font-weight: bold">500</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">default</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">''</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">DECLARE</span><span style="color: #000000">&nbsp;v_schema&nbsp;</span><span style="color: #000000; font-weight: bold">varchar</span><span style="color: #000000">(</span><span style="color: #800000; font-weight: bold">500</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">default</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">''</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008080">--</span><span style="color: #008080">&nbsp;显示总记录数</span><span style="color: #008080"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">DECLARE</span><span style="color: #000000">&nbsp;curPos&nbsp;</span><span style="color: #0000ff">CURSOR</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">FOR</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;table_schema,table_name&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;information_schema.tables&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;table_schema&nbsp;</span><span style="color: #808080">in</span><span style="color: #000000">(dbname)&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;engine</span><span style="color: #808080">=</span><span style="color: #ff0000">'</span><span style="color: #ff0000">InnoDB</span><span style="color: #ff0000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">DECLARE</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">CONTINUE</span><span style="color: #000000">&nbsp;HANDLER&nbsp;</span><span style="color: #0000ff">FOR</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;FOUND&nbsp;</span><span style="color: #0000ff">SET</span><span style="color: #000000">&nbsp;done</span><span style="color: #808080">=</span><span style="color: #800000; font-weight: bold">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;</span><span style="color: #ff00ff">count</span><span style="color: #000000">(</span><span style="color: #808080">*</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;information_schema.tables&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;table_schema&nbsp;</span><span style="color: #808080">in</span><span style="color: #000000">(dbname)&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;engine</span><span style="color: #808080">=</span><span style="color: #ff0000">'</span><span style="color: #ff0000">InnoDB</span><span style="color: #ff0000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">OPEN</span><span style="color: #000000">&nbsp;curPos;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;REPEAT<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">FETCH</span><span style="color: #000000">&nbsp;curPos&nbsp;</span><span style="color: #0000ff">INTO</span><span style="color: #000000">&nbsp;v_schema,v_tbname;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">not</span><span style="color: #000000">&nbsp;done&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">&nbsp;</span><span style="color: #008000">@sql_delete</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">concat(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">alter&nbsp;table&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #000000">,v_schema,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">.</span><span style="color: #ff0000">'</span><span style="color: #000000">,v_tbname,&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">&nbsp;engine=</span><span style="color: #ff0000">''</span><span style="color: #ff0000">MyISAM</span><span style="color: #ff0000">'''</span><span style="color: #000000">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&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;</span><span style="color: #0000ff">prepare</span><span style="color: #000000">&nbsp;sql_del&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;</span><span style="color: #008000">@sql_delete</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">execute</span><span style="color: #000000">&nbsp;sql_del;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">end</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;UNTIL&nbsp;done&nbsp;</span><span style="color: #0000ff">END</span><span style="color: #000000">&nbsp;REPEAT;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">close</span><span style="color: #000000">&nbsp;curPos;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">end</span><span style="color: #000000">;</span></div><img src ="http://www.cppblog.com/API/aggbug/190421.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-09-12 18:06 <a href="http://www.cppblog.com/API/archive/2012/09/12/190421.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>合服时注意事项</title><link>http://www.cppblog.com/API/archive/2012/09/06/189659.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Thu, 06 Sep 2012 03:02:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/09/06/189659.html</guid><wfw:comment>http://www.cppblog.com/API/comments/189659.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/09/06/189659.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/189659.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/189659.html</trackback:ping><description><![CDATA[<div>1. 注意新生成的ID是否有充突<br />2. 删除数据时，不要使用delete from tbl where fd1 in(select fb1 from tb2);这样的句释，应该使用<br />&nbsp;&nbsp; delete tb1 from tb1,tb2 where tb1.fd1 = tb2.fd1;<br /><br />3.在合数据时，注意存储过程的可再入性，即，已经合过的账号信息，应该注意标记，以免意外情况打断时<br />&nbsp;&nbsp; 可以继续执行存储过程。<br /><br />4.如果一个存储过程合并比较复杂，账号信息多，注意用取模的方式分开执行。比如分10次，或者更多次数去执行合并存储过程。<br />&nbsp;&nbsp;&nbsp;&nbsp;如果N条SQL可以开多个终端分开同时执行。<br /><br />5.注意在非常耗时的存储过程中，加入执行进度，可以即时知道执行情况。</div><img src ="http://www.cppblog.com/API/aggbug/189659.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-09-06 11:02 <a href="http://www.cppblog.com/API/archive/2012/09/06/189659.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql多表关联删除</title><link>http://www.cppblog.com/API/archive/2012/09/05/189557.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Wed, 05 Sep 2012 06:57:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/09/05/189557.html</guid><wfw:comment>http://www.cppblog.com/API/comments/189557.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/09/05/189557.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/189557.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/189557.html</trackback:ping><description><![CDATA[<div>DELETE删除多表数据，怎样才能同时删除多个关联表的数据呢？这里做了深入的解释：<br />1 <wbr><wbr><wbr>delete from t1 where 条件<br />2 <wbr><wbr><wbr>delete t1 from t1 where 条件<br />3 <wbr><wbr><wbr>delete t1 from t1,t2 where 条件<br />4 <wbr><wbr><wbr>delete t1,t2 from t1,t2 where 条件<br /><br /><br />前 3者是可行的，第4者不可行。<br /><wbr>也就是简单用delete语句无法进行多表删除数据操作，不过可以建立级联删除，在两个表之间建立级联删除关系，则可以实现删除一个表的数据时，同时删除另一个表中相关的数据。<br /><br />1、从数据表t1中把那些id值在数据表t2里有匹配的记录全删除掉1 <wbr><wbr><wbr>DELETE t1 FROM t1,t2 WHERE t1.id=t2.id 或 DELETE FROM t1 USING t1,t2 WHERE t1.id=t2.id<br /><br /><br />2、从数据表t1里在数据表t2里没有匹配的记录查找出来并删除掉1 <wbr><wbr><wbr>DELETE t1 FROM t1 LEFT JOIN T2 ON t1.id=t2.id WHERE t2.id IS NULL 或 DELETE FROM t1,USING t1 LEFT JOIN T2 ON t1.id=t2.id WHERE t2.id IS NULL<br /><br /><br />3、 从两个表中找出相同记录的数据并把两个表中的数据都删除掉1 <wbr><wbr><wbr>DELETE t1,t2 from t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t1.id=25<br /><br /><br />注意此处的delete t1,t2 from 中的t1,t2不能是别名<br /><br />如：1 <wbr><wbr><wbr>delete t1,t2 from table_name as t1 left join table2_name as t2 on t1.id=t2.id where table_name.id=25<br /><br /><br />在数据里面执行是错误的（MYSQL 版本不小于5.0在5.0中是可以的）<br /><br />上述语句改 写成1 <wbr><wbr><wbr>delete table_name,table2_name from table_name as t1 left join table2_name as t2 on t1.id=t2.id where table_name.id=25<br /><br /><br />在数据里面执行是错误的（MYSQL 版本小于5.0在5.0中是可以的）<br /></div><img src ="http://www.cppblog.com/API/aggbug/189557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-09-05 14:57 <a href="http://www.cppblog.com/API/archive/2012/09/05/189557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql修改表引擎</title><link>http://www.cppblog.com/API/archive/2012/09/04/189394.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Tue, 04 Sep 2012 03:07:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/09/04/189394.html</guid><wfw:comment>http://www.cppblog.com/API/comments/189394.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/09/04/189394.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/189394.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/189394.html</trackback:ping><description><![CDATA[ALTER TABLE tbl_achievement_51&nbsp; ENGINE=MyISAM;<img src ="http://www.cppblog.com/API/aggbug/189394.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-09-04 11:07 <a href="http://www.cppblog.com/API/archive/2012/09/04/189394.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql 的innodb优化</title><link>http://www.cppblog.com/API/archive/2012/07/30/185629.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Mon, 30 Jul 2012 07:00:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/07/30/185629.html</guid><wfw:comment>http://www.cppblog.com/API/comments/185629.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/07/30/185629.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/185629.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/185629.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; innodb_flush_logs_at_trx_commit 是否为Innodb比MyISAM慢1000倍而头大？<br />&nbsp;&nbsp;&nbsp; 看来也许你忘了修改这个参数了。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 默认值是 1，这意味着每次提交的更新事务（或者每个事务之外的语句）都会刷新到磁盘中，而这相当耗费资源，尤其是没有电池备用缓存时。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 很多应用程序，尤其是从 MyISAM转变过来的那些，把它的值设置为 2 就可以了，也就是不把日志刷新到磁盘上，而只刷新到操<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 作系统的缓存上。日志仍然会每秒刷新到磁盘中去，因此通常不会丢失每秒1-2次更新的消耗。如果设置为 0 就快很多了，不过也<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 相对不安全了。MySQL服务器崩溃时就会丢失一些事务。设置为 2 指挥丢失刷新到操作系统缓存的那部分事务。<img src ="http://www.cppblog.com/API/aggbug/185629.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-07-30 15:00 <a href="http://www.cppblog.com/API/archive/2012/07/30/185629.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mysql另一种插入语法(如果唯一冲突,则不插入,执行更新)</title><link>http://www.cppblog.com/API/archive/2012/06/14/178765.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Thu, 14 Jun 2012 02:02:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/06/14/178765.html</guid><wfw:comment>http://www.cppblog.com/API/comments/178765.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/06/14/178765.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/178765.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/178765.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">INSERT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">INTO</span><span style="color: #000000">&nbsp;tbl_user_private_info(</span><span style="color: #ff00ff">user_id</span><span style="color: #000000">,&nbsp;nick_name,&nbsp;sex,&nbsp;sub_type,&nbsp;device_type,&nbsp;tag)&nbsp;</span><span style="color: #0000ff">values</span><span style="color: #000000">(&nbsp;inUserId,&nbsp;inNickName,&nbsp;inSex,&nbsp;inSubType,&nbsp;inDeviceType,&nbsp;inTag)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">ON</span><span style="color: #000000">&nbsp;DUPLICATE&nbsp;</span><span style="color: #0000ff">KEY</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">UPDATE</span><span style="color: #000000">&nbsp;nick_name</span><span style="color: #808080">=</span><span style="color: #000000">inNickName,&nbsp;sex</span><span style="color: #808080">=</span><span style="color: #000000">inSex,&nbsp;sub_type</span><span style="color: #808080">=</span><span style="color: #000000">inSubType,&nbsp;device_type</span><span style="color: #808080">=</span><span style="color: #000000">inDeviceType,&nbsp;tag</span><span style="color: #808080">=</span><span style="color: #000000">inTag;</span></div><img src ="http://www.cppblog.com/API/aggbug/178765.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-06-14 10:02 <a href="http://www.cppblog.com/API/archive/2012/06/14/178765.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>捕获mysql异常</title><link>http://www.cppblog.com/API/archive/2012/05/06/173819.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Sun, 06 May 2012 06:41:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/05/06/173819.html</guid><wfw:comment>http://www.cppblog.com/API/comments/173819.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/05/06/173819.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/173819.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/173819.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img id="Codehighlighter1_0_74_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_74_Open_Text.style.display='none'; Codehighlighter1_0_74_Closed_Image.style.display='inline'; Codehighlighter1_0_74_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_0_74_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_0_74_Closed_Text.style.display='none'; Codehighlighter1_0_74_Open_Image.style.display='inline'; Codehighlighter1_0_74_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_0_74_Closed_Text">/**/</span><span id="Codehighlighter1_0_74_Open_Text"><span style="color: #008080">/*</span><span style="color: #008080">*mySql中是否能有SQLserver的@@error变量呢，或者如c#中的try&nbsp;catch语法呢。&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />答案是肯定的，实例代码如下：*</span><span style="color: #008080">*/</span></span><span style="color: #000000">&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">DROP</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">PROCEDURE</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">IF</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">EXISTS</span><span style="color: #000000">&nbsp;sp_call_jobs;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">CREATE</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">PROCEDURE</span><span style="color: #000000">&nbsp;sp_call_jobs()&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;DETERMINISTIC&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;SQL&nbsp;SECURITY&nbsp;DEFINER&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COMMENT&nbsp;</span><span style="color: #ff0000">''</span><span style="color: #000000">&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">BEGIN</span><span style="color: #000000">&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">declare</span><span style="color: #000000">&nbsp;_row,_err,_</span><span style="color: #ff00ff">count</span><span style="color: #000000">&nbsp;</span><span style="color: #000000; font-weight: bold">int</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">default</span><span style="color: #000000">&nbsp;</span><span style="color: #800000; font-weight: bold">0</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">DECLARE</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">CONTINUE</span><span style="color: #000000">&nbsp;&nbsp;HANDLER&nbsp;</span><span style="color: #0000ff">FOR</span><span style="color: #000000">&nbsp;SQLEXCEPTION,SQLWARNING,</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;FOUND&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">&nbsp;_err</span><span style="color: #808080">=</span><span style="color: #800000; font-weight: bold">1</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;_row</span><span style="color: #808080">&lt;</span><span style="color: #800000; font-weight: bold">3</span><span style="color: #000000">&nbsp;DO&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;START&nbsp;</span><span style="color: #0000ff">TRANSACTION</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">insert</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">into</span><span style="color: #000000">&nbsp;t1(cond_val)</span><span style="color: #0000ff">values</span><span style="color: #000000">(</span><span style="color: #0000ff">null</span><span style="color: #000000">);&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">COMMIT</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;_err</span><span style="color: #808080">=</span><span style="color: #800000; font-weight: bold">1</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">&nbsp;_</span><span style="color: #ff00ff">count</span><span style="color: #808080">=</span><span style="color: #000000">_</span><span style="color: #ff00ff">count</span><span style="color: #808080">+</span><span style="color: #800000; font-weight: bold">1</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">end</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">&nbsp;_row</span><span style="color: #808080">=</span><span style="color: #000000">_row</span><span style="color: #808080">+</span><span style="color: #800000; font-weight: bold">1</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">end</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;_</span><span style="color: #ff00ff">count</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">END</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img id="Codehighlighter1_597_862_Open_Image" onclick="this.style.display='none'; Codehighlighter1_597_862_Open_Text.style.display='none'; Codehighlighter1_597_862_Closed_Image.style.display='inline'; Codehighlighter1_597_862_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_597_862_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_597_862_Closed_Text.style.display='none'; Codehighlighter1_597_862_Open_Image.style.display='inline'; Codehighlighter1_597_862_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_597_862_Closed_Text">/**/</span><span id="Codehighlighter1_597_862_Open_Text"><span style="color: #008080">/*</span><span style="color: #008080">*语句：&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />DECLARE&nbsp;CONTINUE&nbsp;&nbsp;HANDLER&nbsp;FOR&nbsp;SQLEXCEPTION,SQLWARNING,NOT&nbsp;FOUND&nbsp;set&nbsp;_err=1;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;作用是当遇到SQLEXCEPTION,SQLWARNING,NOT&nbsp;FOUND&nbsp;错误时，设置_err=1并执行CONTINUE操作，即继续执行后面的语句。&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;这就与c＃中的try&nbsp;catch语法很像。&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />而且在执行可能出错的语句的时候我们用事务语句：START&nbsp;TRANSACTION;&nbsp;&#8230;&#8230;&nbsp;COMMIT;&nbsp;可以保证完整性。&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />&nbsp;*</span><span style="color: #008080">*/</span></span><span style="color: #000000">&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/API/aggbug/173819.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-05-06 14:41 <a href="http://www.cppblog.com/API/archive/2012/05/06/173819.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>shell操作mysql</title><link>http://www.cppblog.com/API/archive/2012/03/28/169251.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Wed, 28 Mar 2012 02:58:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/03/28/169251.html</guid><wfw:comment>http://www.cppblog.com/API/comments/169251.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/03/28/169251.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/169251.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/169251.html</trackback:ping><description><![CDATA[<span style="color: red; font-size: 18pt">方案1 </span>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">mysql&nbsp;</span><span style="color: #808080">-</span><span style="color: #000000">uuser&nbsp;</span><span style="color: #808080">-</span><span style="color: #000000">ppasswd&nbsp;</span><span style="color: #808080">-</span><span style="color: #000000">e"</span><span style="color: #0000ff">insert</span><span style="color: #000000">&nbsp;LogTable&nbsp;</span><span style="color: #0000ff">values</span><span style="color: #000000">(<img alt="" src="http://www.cppblog.com/Images/dot.gif" />)"&nbsp;&nbsp;</span></div><br />
<div><strong>优点</strong>：语句简单</div>
<div><strong>缺点</strong>：支持的sql相对简单</div><br /><br />
<h2><strong style="color: red; font-size: 18pt">方案2</strong></h2>
<div><span style="font-family: monospace">准备一个sql脚本，名字为update.sql，例如：<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #0000ff">CREATE</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">TABLE</span><span style="color: #000000">&nbsp;`</span><span style="color: #ff00ff">user</span><span style="color: #000000">`&nbsp;(&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;`id`&nbsp;</span><span style="color: #000000; font-weight: bold">varchar</span><span style="color: #000000">(</span><span style="color: #800000; font-weight: bold">36</span><span style="color: #000000">)&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">NULL</span><span style="color: #000000">&nbsp;COMMENT&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">主键</span><span style="color: #ff0000">'</span><span style="color: #000000">,&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;`username`&nbsp;</span><span style="color: #000000; font-weight: bold">varchar</span><span style="color: #000000">(</span><span style="color: #800000; font-weight: bold">50</span><span style="color: #000000">)&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">NULL</span><span style="color: #000000">&nbsp;COMMENT&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">用户名</span><span style="color: #ff0000">'</span><span style="color: #000000">,&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;`password`&nbsp;</span><span style="color: #000000; font-weight: bold">varchar</span><span style="color: #000000">(</span><span style="color: #800000; font-weight: bold">50</span><span style="color: #000000">)&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">NULL</span><span style="color: #000000">&nbsp;COMMENT&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">用户密码</span><span style="color: #ff0000">'</span><span style="color: #000000">,&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;`createdate`&nbsp;date&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">NULL</span><span style="color: #000000">&nbsp;COMMENT&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">创建时间</span><span style="color: #ff0000">'</span><span style="color: #000000">,&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;`age`&nbsp;</span><span style="color: #000000; font-weight: bold">int</span><span style="color: #000000">(</span><span style="color: #800000; font-weight: bold">11</span><span style="color: #000000">)&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">NULL</span><span style="color: #000000">&nbsp;COMMENT&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">年龄</span><span style="color: #ff0000">'</span><span style="color: #000000">,&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;</span><span style="color: #0000ff">PRIMARY</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">KEY</span><span style="color: #000000">&nbsp;&nbsp;(`id`)&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />)&nbsp;ENGINE</span><span style="color: #808080">=</span><span style="color: #000000">MyISAM&nbsp;</span><span style="color: #0000ff">DEFAULT</span><span style="color: #000000">&nbsp;CHARSET</span><span style="color: #808080">=</span><span style="color: #000000">utf8&nbsp;COMMENT</span><span style="color: #808080">=</span><span style="color: #ff0000">'</span><span style="color: #ff0000">用户信息表</span><span style="color: #ff0000">'</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">DROP</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">TABLE</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">IF</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">EXISTS</span><span style="color: #000000">&nbsp;`visit_log`;&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">CREATE</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">TABLE</span><span style="color: #000000">&nbsp;`visit_log`&nbsp;(&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;`id`&nbsp;</span><span style="color: #000000; font-weight: bold">varchar</span><span style="color: #000000">(</span><span style="color: #800000; font-weight: bold">36</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000; font-weight: bold">character</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">&nbsp;utf8&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">NULL</span><span style="color: #000000">,&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;`type`&nbsp;</span><span style="color: #000000; font-weight: bold">int</span><span style="color: #000000">(</span><span style="color: #800000; font-weight: bold">11</span><span style="color: #000000">)&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">NULL</span><span style="color: #000000">,&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;`content`&nbsp;</span><span style="color: #000000; font-weight: bold">text</span><span style="color: #000000">&nbsp;</span><span style="color: #000000; font-weight: bold">character</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">&nbsp;utf8&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">NULL</span><span style="color: #000000">,&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;`createdate`&nbsp;date&nbsp;</span><span style="color: #808080">NOT</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">NULL</span><span style="color: #000000">,&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;&nbsp;</span><span style="color: #0000ff">PRIMARY</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">KEY</span><span style="color: #000000">&nbsp;&nbsp;(`id`)&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />)&nbsp;ENGINE</span><span style="color: #808080">=</span><span style="color: #000000">MyISAM&nbsp;</span><span style="color: #0000ff">DEFAULT</span><span style="color: #000000">&nbsp;CHARSET</span><span style="color: #808080">=</span><span style="color: #000000">latin1&nbsp;COMMENT</span><span style="color: #808080">=</span><span style="color: #ff0000">'</span><span style="color: #ff0000">访问日志</span><span style="color: #ff0000">'</span><span style="color: #000000">;&nbsp;&nbsp;</span></div></span></div><br />新建一个update_mysql.sh，内容如下： 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">use&nbsp;chbdb;&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />source&nbsp;update.sql<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span></div><br /><span style="font-family: monospace">然后执行如下命令：<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">cat&nbsp;update_mysql.sh&nbsp;</span><span style="color: #000000">|</span><span style="color: #000000">&nbsp;mysql&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">user</span><span style="color: #000000">=</span><span style="color: #000000">root&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">ppassword&nbsp;&nbsp;</span></div></span><br />
<div><span style="font-family: monospace"><strong>优点</strong></span><span style="font-family: monospace">：支持复杂的sql脚本</span></div>
<div><span style="font-family: monospace"><strong>缺点：</strong></span></div>
<div><span style="font-family: monospace">1&gt; 需要两个文件：update.sql和update_mysql.sh</span></div>
<div><span style="font-family: monospace">2&gt; 一旦中间出错，之后脚本就不会执行，例如：</span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">如果第一张表已经存在，则会报出如下异常：</span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">ERROR 1050 (42S01) at line 1 in file: 'update.sql': Table 'user' already exists</span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">然后脚本退出，第二张表也就无法创建。</span></div><br /><br /><span style="font-family: monospace; color: red; font-size: 18pt">方案3</span><br />新建一个shell脚本，格式如下：<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" /><span style="color: #008000">#</span><span style="color: #008000">!/bin/bash&nbsp;&nbsp;&nbsp;</span><span style="color: #008000"><br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" /></span><span style="color: #000000">mysql&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">u</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">h</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">p</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">EOF&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" />Your&nbsp;SQL&nbsp;script.&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" />EOF&nbsp;&nbsp;</span></div><br />
<div><span style="font-family: monospace"><strong>优点：</strong></span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">1&gt;支持复杂的sql脚本</span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">2&gt;无需其它额外文件</span></div>
<div><span style="font-family: monospace"><strong>缺点：</strong></span></div>
<div><span style="font-family: monospace">1&gt; 表名、字段不能使用单引号，需要修改原有sql语句</span></div>
<div><span style="font-family: monospace">2&gt; 一旦中间出错，之后脚本就不会执行，例如：</span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">如果第一张表已经存在，则会报出如下异常：</span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">ERROR 1050 (42S01) at line 1 in file: 'update.sql': </span><span style="font-family: monospace; color: #000000">Tab</span><span style="font-family: monospace; color: #000000">le </span><span style="font-family: monospace; color: #000000">'us</span><span style="font-family: monospace; color: #000000">er' a</span><span style="font-family: monospace; color: #000000">lready </span><span style="font-family: monospace">exists</span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">然后脚本退出，第二张表也就无法创建。</span></div><br /><br />方案4<br />准备一个sql脚本，如update.sql，然后执行如下命令：<br /><br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" /><span style="color: #000000">mysql&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">uroot&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">ppassword&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;update.sql&nbsp;&nbsp;</span></div><br />
<div><span style="font-family: monospace"><strong>优点：<span style="font-weight: normal">支持复杂的sql脚本</span></strong></span></div>
<div><span style="font-family: monospace"><strong>缺点：</strong></span></div>
<div><span style="font-family: monospace">1&gt; 一旦中间出错，之后脚本就不会执行，例如：</span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">如果第一张表已经存在，则会报出如下异常：</span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">ERROR 1050 (42S01) at line 1 in file: 'update.sql': Table 'user' already exists</span></div>
<div style="padding-left: 30px"><span style="font-family: monospace">然后脚本退出，第二张表也就无法创建。</span></div>
<div>&nbsp;</div>
<div>&nbsp;<br /><br /></div><img src ="http://www.cppblog.com/API/aggbug/169251.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-03-28 10:58 <a href="http://www.cppblog.com/API/archive/2012/03/28/169251.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux mysql用户管理 </title><link>http://www.cppblog.com/API/archive/2012/03/27/169165.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Tue, 27 Mar 2012 09:08:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/03/27/169165.html</guid><wfw:comment>http://www.cppblog.com/API/comments/169165.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/03/27/169165.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/169165.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/169165.html</trackback:ping><description><![CDATA[<div class="postBody">
<div id="cnblogs_post_body">
<p>一、root用户密码的维护：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 由于安装MySQL完后,MySQL会自动提供一个不带密码的root用户，为了安全起见给root设置密码：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #008000">#mysqladmin -u root password 123</span> (123为密码，也可以写成:'123'或"123") ；</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 设置密码后登入时就不能直接输入mysql了，必须跟些参数了,如下：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost ~]<span style="color: #008000"># mysql -u root -p</span> （-u 后跟登入的用户名，-p 提示要密码登入）<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enter password:(输入密码)</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 修改密码：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost ~] <span style="color: #008000">#mysqladmin -u root&nbsp; -p&nbsp; password&nbsp; 123456</span> (password 后跟的是要更新的新密码)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enter password:(输入原始密码，回车即可)</p>
<p>&nbsp;</p>
<p>二、其他用户的增加和删除：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 以root用户登入，在mysql中有一张mysql.user表是存储MySQL中所有用户的信息表，所以可以直接增加删除这个表的记录就可增加和删除用户；</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 1.添加用户（有两种形式）：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A.mysql&gt; <span style="color: #008000">grant all on *.* to yushan@"%" identified by "123" ;</span> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mysql&gt;<span style="color: #008000">flush&nbsp;privileges;</span> (刷新系统权限表)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (执行完会在mysql.user表插入一条记录，all表示所有权限(包括增 删 改 查等权限)， *.* 表示所有数据库，yushan为添加的用户名，123为密码,%为匹配的所有主机，上面的信息都可以指定如grant&nbsp;select,update&nbsp;on db.*&nbsp;to yushan@localhost&nbsp;identified&nbsp;by&nbsp;'123";)</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp; B.直接对mysql.user添加一条记录</p>
<p>&nbsp;&nbsp; mysql&gt;&nbsp;<span style="color: #008000">insert&nbsp;into&nbsp;mysql.user(Host,User,Password)&nbsp;values("localhost","yusuhan",password("123"));</span> <br />&nbsp;&nbsp; mysql&gt;<span style="color: #008000">flush&nbsp;privileges;</span> <br />&nbsp;&nbsp; 这样就创建了一个名为：yushan 密码为：123<span style="color: #993300"> (密码是经过加密的</span> ) 的用户，不过这样没有权限因为只添加了三个字段，也可通过grant添&nbsp; 加权限：</p>
<p>&nbsp;&nbsp; mysql&gt;grant&nbsp;all&nbsp; on *.*&nbsp;to yushan@localhost&nbsp;identified&nbsp;by&nbsp;'123";<br />&nbsp;&nbsp; mysql&gt;flush&nbsp;privileges;(刷新系统权限表)</p>
<p>&nbsp;&nbsp; （这种好像有点啰嗦了。直接用grant不久得了）</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp; 添加完用户 如果要远程登入MySQL,必须跟上主机Ip 如下：</p>
<p>&nbsp;&nbsp; [root@localhost ~]# <span style="color: #008000">mysql -u yushan -p </span><span style="color: #ff6600">-h 192.168.59.123</span> <br />&nbsp;&nbsp; Enter password:(输入密码)</p>
<p>&nbsp;</p>
<p>&nbsp; 2.删除用户 ：</p>
<p>&nbsp;&nbsp; mysql&gt;<span style="color: #008000">delete from mysql.user where user ='yushan' ;</span></p>
<p>&nbsp;&nbsp; mysql&gt;<span style="color: #008000">flush&nbsp;privileges;</span> (刷新系统权限表)</p>
<p>&nbsp;</p>
<p>&nbsp; 其他用户的密码修改与root的一样，在这里无论是添加或是删除操作后必须来个<span style="color: #008000">flush&nbsp;privileges;<span style="color: #000000">这样才能起作用特别是删除用户后，如果未执行，被删除的用户还可登入，以上都是在MySQL root用户下操作，为了MySQL的安全，应该给用户指定相应的权限<br /></span></span></p>
<p>&nbsp;<img alt="" src="http://www.cnblogs.com/blong880123/aggbug/2269451.html?type=1&amp;webview=1" width="1" height="1" /> <!--end: topics 文章、评论容器-->
</p></div></div>
<div id="comment_form" class="commentform">
<div id="divCommentShow"></div></div><img src ="http://www.cppblog.com/API/aggbug/169165.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-03-27 17:08 <a href="http://www.cppblog.com/API/archive/2012/03/27/169165.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mysql安装</title><link>http://www.cppblog.com/API/archive/2012/03/27/169153.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Tue, 27 Mar 2012 07:22:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/03/27/169153.html</guid><wfw:comment>http://www.cppblog.com/API/comments/169153.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/03/27/169153.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/169153.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/169153.html</trackback:ping><description><![CDATA[当安装时出现<br />file /usr/share/mysql/charsets/README from install of MySQL-server-5.5.22-1.linux2.6.x86_64 conflicts with file from package mysql-libs-5.1.52-1.el6_0.1.x86_64<br /><br />或者将以前的删掉用<br />rpm -qa|grep mysql<br />rpm -e ***<br />yum -y remove mysql-libs-5.1*<br /><br />删除掉所有的mysql之前安装的内容.再安装即可 <br /><br /><br /><br />
<p>1.连接mysql<br />------------------------------------------------<br />格式： mysql -h主机地址 -u用户名 －p用户密码</p>
<p>2.退出mysql<br />------------------------------------------------<br />#exit</p>
<p>3.修改密码<br />------------------------------------------------<br />格式：mysqladmin -u用户名 -p旧密码&nbsp; password 新密码</p>
<p>例1：给root加个密码123456<br /># /usr/bin/mysqladmin -u root password 123456</p>
<p>再将root的密码改为djg345<br />#mysqladmin -uroot -p123456 password 654321</p>
<p><br />4.增加新用户<br />------------------------------------------------<br />grant select on 数据库.* to 用户名@登录主机 identified by "密码"</p>
<p>grant select,insert,update,delete on *.* to <a href='&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#116;&#101;&#115;&#116;&#49;&#64;&#34;&#37;' href_cetemp='mailto:test1@"%'>test1@"%</a>" Identified by "abc";<br />grant select,insert,update,delete on mydb.* to <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#116;&#101;&#115;&#116;&#50;&#64;&#108;&#111;&#99;&#97;&#108;&#104;&#111;&#115;&#116;">test2@localhost</a> identified by "abc";<br />grant select,insert,update,delete on mydb.* to <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#116;&#101;&#115;&#116;&#50;&#64;&#108;&#111;&#99;&#97;&#108;&#104;&#111;&#115;&#116;">test2@localhost</a> identified by "";</p>
<p>grant select,insert,update,delete on *.* to <a href='&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#116;&#101;&#115;&#116;&#49;&#64;&#34;&#37;' href_cetemp='mailto:test1@"%'>test1@"%</a>"；</p>
<p>5.mysql段错误<br />------------------------------------------------<br />export LANG=en_US</p>
<p><br />二、显示命令 <br />1、显示数据库列表。 <br />show databases; <br />2、显示库中的数据表： <br />use mysql;<br />show tables; <br />3、显示数据表的结构： <br />describe 表名; <br />4、建库： <br />create database 库名; <br />5、建表： <br />use 库名； <br />create table 表名 (字段设定列表)； <br />6、删库和删表: <br />drop database 库名; <br />drop table 表名； <br />7、将表中记录清空： <br />delete from 表名; <br />8、显示表中的记录： <br />select * from 表名</p>
<p>9.<br />service mysql restart</p>
<p>本人示例：<br />1.安装完后</p>
<p>给root加个密码loveping99<br />#/usr/bin/mysqladmin -uroot password loveping99</p>
<p>登录<br />#mysql -h 127.0.0.1 -uroot -ploveping99<br />#exit</p>
<p>修改密码(新密码为：game2009abc)<br />#mysqladmin -uroot -ploveping99 password game2009abc</p>
<p>再次登录(不加-h默认本地登录)<br />#mysql -uroot -pgame2009abc</p>
<p><br /><span style="color: red">使用shell执行脚本&nbsp;</span><br /></p>
<p>&nbsp;installDB.sh内容如下：<br />mysql -uroot -p123456 &lt;db.sql<br /></p><img src ="http://www.cppblog.com/API/aggbug/169153.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-03-27 15:22 <a href="http://www.cppblog.com/API/archive/2012/03/27/169153.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql case 语言使用(按日期插表)</title><link>http://www.cppblog.com/API/archive/2012/03/14/167870.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Wed, 14 Mar 2012 05:10:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/03/14/167870.html</guid><wfw:comment>http://www.cppblog.com/API/comments/167870.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/03/14/167870.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/167870.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/167870.html</trackback:ping><description><![CDATA[<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">DROP</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">PROCEDURE</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">IF</span><span style="color: #000000; ">&nbsp;</span><span style="color: #808080; ">EXISTS</span><span style="color: #000000; ">&nbsp;`Sp_SendRequest`;<br /><br />DELIMITER&nbsp;;;<br /></span><span style="color: #0000FF; ">CREATE</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">PROCEDURE</span><span style="color: #000000; ">&nbsp;Sp_SendRequest(&nbsp;<br />inRequestID&nbsp;</span><span style="color: #000000; font-weight: bold; ">Varchar</span><span style="color: #000000; ">(</span><span style="color: #800000; font-weight: bold; ">32</span><span style="color: #000000; ">),<br />inRequestTagID&nbsp;</span><span style="color: #000000; font-weight: bold; ">int</span><span style="color: #000000; ">(</span><span style="color: #800000; font-weight: bold; ">11</span><span style="color: #000000; ">),<br />inSendID&nbsp;</span><span style="color: #000000; font-weight: bold; ">varchar</span><span style="color: #000000; ">(</span><span style="color: #800000; font-weight: bold; ">30</span><span style="color: #000000; ">),<br />inOwnerID&nbsp;</span><span style="color: #000000; font-weight: bold; ">varchar</span><span style="color: #000000; ">(</span><span style="color: #800000; font-weight: bold; ">30</span><span style="color: #000000; ">)<br />)<br /></span><span style="color: #0000FF; ">BEGIN</span><span style="color: #000000; "><br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">&nbsp;</span><span style="color: #008000; ">@days</span><span style="color: #000000; ">&nbsp;:</span><span style="color: #808080; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">0</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">&nbsp;</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">&nbsp;:</span><span style="color: #808080; ">=</span><span style="color: #000000; ">&nbsp;UNIX_TIMESTAMP();<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #0000FF; ">select</span><span style="color: #000000; ">&nbsp;from_unixtime(</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">,</span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">%d</span><span style="color: #FF0000; ">'</span><span style="color: #000000; ">)&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;</span><span style="color: #008000; ">@days</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;</span><span style="color: #FF00FF; ">case</span><span style="color: #000000; ">&nbsp;</span><span style="color: #008000; ">@days</span><span style="color: #000000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_01(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">2</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_02(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">3</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_03(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">4</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_04(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">5</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_05(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">6</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_06(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">7</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_07(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">8</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_08(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">9</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_09(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">10</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_10(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">11</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_11(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">12</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_12(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">13</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_13(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">14</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_14(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">15</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_15(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">16</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_16(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">17</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_17(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">18</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_18(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">19</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_19(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">20</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_20(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">21</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_21(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">22</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_22(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">23</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_23(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">24</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_24(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">25</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_25(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">26</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_26(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">27</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_27(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">28</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_28(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">29</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_29(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">30</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_30(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">when</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">31</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_FreeGift_31(RequestID,RequestTagID,SendID,OwnerID,StartTimeStamp)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inRequestID,inRequestTagID,inSendID,inOwnerID,</span><span style="color: #008000; ">@timestamps</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #0000FF; ">end</span><span style="color: #000000; ">&nbsp;</span><span style="color: #FF00FF; ">case</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;<br /></span><span style="color: #0000FF; ">END</span><span style="color: #000000; ">;;<br /></span></div><img src ="http://www.cppblog.com/API/aggbug/167870.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-03-14 13:10 <a href="http://www.cppblog.com/API/archive/2012/03/14/167870.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mysql表</title><link>http://www.cppblog.com/API/archive/2012/03/03/167042.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Sat, 03 Mar 2012 03:35:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/03/03/167042.html</guid><wfw:comment>http://www.cppblog.com/API/comments/167042.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/03/03/167042.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/167042.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/167042.html</trackback:ping><description><![CDATA[<div><span style="color: #ff0000; font-size: 18pt;">存储引擎的选择</span></div><br />1. MyISAM不支持事务，不支持外键，优点是访问速度高，批量插入速度快。假设大量的操作是select、insert，建议采用该存储引擎。但是在我的实际应用中，出现过批量插入过于频繁的时候，当数据量到达一定级别，出现表损坏的情况。<br /><br /><div>2. InnoDB支持事务处理，但是相对于前者，处理效率低一些，并且其索引及数据也更占用磁盘空间。在存储一些关键数据，并需要对其进行事务操作的时候，我们可以选择innodb，当然，我认为他不应该是访问量太大的。</div><br /><div><span style="font-size: 18pt; color: #ff0000;">索引的设计及使用 </span><p>　　怎么设计索引是合理的,这里简要分析下索引的设计及使用。</p> <p>　　1. 索引通常是设置where字句中的列，如果你设置select后的列，这是没有任何意义的。当然你需要对某列进行排序，order by后的列也是可以建成索引的。</p> <p>　　2. 使用唯一索引，主键就是最好的例子，假设你建的索引列，大量都是重复的，例如：性别，那么这样的索引并不会加快搜索速度。至于为什么，请大家自行了解索引的工作原理。</p> <p>　　3. 只要有可能，就要尽量限定索引的长度，例如索引列为 char(100)，在其前10个字符大部分都是唯一的，请设置索引的长度为10，使用短索引可以加快查询速度，并节省硬盘空间。</p> <p>　　4. 索引的左前缀特性，联合索引实质上也是建立了多个的索引，那么是建立联合索引好还是分别建多个索引好呢？显然前者更好，利用左前缀特性，只要联合索引的最左的列被用到，那么索引都会被使用。</p> 　　5. 当然，最后要说的是，不要过度使用索引，索引越多，插入的速度越慢，尤其到数据量庞大时，同时，大量的索引将耗费很多硬盘空间，造成不必要的浪费</div><img src ="http://www.cppblog.com/API/aggbug/167042.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-03-03 11:35 <a href="http://www.cppblog.com/API/archive/2012/03/03/167042.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql获取时间截</title><link>http://www.cppblog.com/API/archive/2012/03/01/166875.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Thu, 01 Mar 2012 07:43:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/03/01/166875.html</guid><wfw:comment>http://www.cppblog.com/API/comments/166875.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/03/01/166875.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/166875.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/166875.html</trackback:ping><description><![CDATA[<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">--</span><span style="color: #008080; ">&nbsp;将时期生成时间截</span><span style="color: #008080; "><br /></span><span style="color: #0000FF; ">Select</span><span style="color: #000000; ">&nbsp;UNIX_TIMESTAMP(now());<br /></span><span style="color: #0000FF; ">Select</span><span style="color: #000000; ">&nbsp;UNIX_TIMESTAMP(</span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">2012-1-1&nbsp;00:00:00</span><span style="color: #FF0000; ">'</span><span style="color: #000000; ">);<br /><br /></span><span style="color: #008080; ">--</span><span style="color: #008080; ">&nbsp;将时间截转成日期格式</span><span style="color: #008080; "><br /></span><span style="color: #0000FF; ">select</span><span style="color: #000000; ">&nbsp;from_unixtime(</span><span style="color: #800000; font-weight: bold; ">1330509529</span><span style="color: #000000;">);<br /></span></div><img src ="http://www.cppblog.com/API/aggbug/166875.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-03-01 15:43 <a href="http://www.cppblog.com/API/archive/2012/03/01/166875.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>取得受影响行数</title><link>http://www.cppblog.com/API/archive/2012/02/15/165641.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Wed, 15 Feb 2012 01:35:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2012/02/15/165641.html</guid><wfw:comment>http://www.cppblog.com/API/comments/165641.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2012/02/15/165641.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/165641.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/165641.html</trackback:ping><description><![CDATA[<div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">1.通过以下SQL可以获取对应的select,与update delete insert返回的行数：</span><br />FOUND_ROWS() : select <br />ROW_COUNT()&nbsp; : update delete insert</div><br />简单示例：<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">DROP</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">TABLE</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">IF</span><span style="color: #000000; ">&nbsp;</span><span style="color: #808080; ">EXISTS</span><span style="color: #000000; ">&nbsp;Tbl_MarketLimit;<br /><br /></span><span style="color: #0000FF; ">CREATE</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">TABLE</span><span style="color: #000000; ">&nbsp;Tbl_MarketLimit&nbsp;(<br />&nbsp;&nbsp;ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold; ">int</span><span style="color: #000000; ">&nbsp;(</span><span style="color: #800000; font-weight: bold; ">11</span><span style="color: #000000; ">)&nbsp;</span><span style="color: #808080; ">not</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">&nbsp;AUTO_INCREMENT,<br />&nbsp;&nbsp;ItemID&nbsp;</span><span style="color: #000000; font-weight: bold; ">int</span><span style="color: #000000; ">(</span><span style="color: #800000; font-weight: bold; ">11</span><span style="color: #000000; ">)&nbsp;</span><span style="color: #808080; ">NOT</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">NULL</span><span style="color: #000000; ">,<br />&nbsp;&nbsp;LimitCount&nbsp;</span><span style="color: #000000; font-weight: bold; ">int</span><span style="color: #000000; ">(</span><span style="color: #800000; font-weight: bold; ">11</span><span style="color: #000000; ">)&nbsp;</span><span style="color: #808080; ">not</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">,<br />&nbsp;&nbsp;IsValidate&nbsp;</span><span style="color: #000000; font-weight: bold; ">int</span><span style="color: #000000; ">(</span><span style="color: #800000; font-weight: bold; ">2</span><span style="color: #000000; ">)&nbsp;</span><span style="color: #808080; ">not</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">default</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; ">,<br />&nbsp;&nbsp;</span><span style="color: #0000FF; ">PRIMARY</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">KEY</span><span style="color: #000000; ">&nbsp;(`ID`),<br />&nbsp;&nbsp;</span><span style="color: #0000FF; ">KEY</span><span style="color: #000000; ">&nbsp;ItemID_index&nbsp;(ItemID)<br />)&nbsp;ENGINE</span><span style="color: #808080; ">=</span><span style="color: #000000; ">InnoDB&nbsp;</span><span style="color: #0000FF; ">DEFAULT</span><span style="color: #000000; ">&nbsp;CHARSET</span><span style="color: #808080; ">=</span><span style="color: #000000; ">utf8;<br /><br /><br /><br /></span><span style="color: #0000FF; ">DROP</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">PROCEDURE</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">IF</span><span style="color: #000000; ">&nbsp;</span><span style="color: #808080; ">EXISTS</span><span style="color: #000000; ">&nbsp;Sp_MarketLimit;<br /><br />DELIMITER&nbsp;;;<br /></span><span style="color: #0000FF; ">CREATE</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">PROCEDURE</span><span style="color: #000000; ">&nbsp;Sp_MarketLimit(&nbsp;<br />inItemID&nbsp;</span><span style="color: #000000; font-weight: bold; ">int</span><span style="color: #000000; ">(</span><span style="color: #800000; font-weight: bold; ">11</span><span style="color: #000000; ">),<br />inLimitCount&nbsp;</span><span style="color: #000000; font-weight: bold; ">int</span><span style="color: #000000; ">(</span><span style="color: #800000; font-weight: bold; ">11</span><span style="color: #000000; ">)<br />)<br /></span><span style="color: #0000FF; ">BEGIN</span><span style="color: #000000; "><br />&nbsp;&nbsp;</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">&nbsp;</span><span style="color: #008000; ">@IsSucc</span><span style="color: #000000; ">&nbsp;</span><span style="color: #808080; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">0</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;</span><span style="color: #0000FF; ">update</span><span style="color: #000000; ">&nbsp;Tbl_MarketLimit&nbsp;</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">&nbsp;LimitCount</span><span style="color: #808080; ">=</span><span style="color: #000000; ">inLimitCount&nbsp;</span><span style="color: #0000FF; ">where</span><span style="color: #000000; ">&nbsp;ItemID</span><span style="color: #808080; ">=</span><span style="color: #000000; ">inItemID&nbsp;</span><span style="color: #808080; ">and</span><span style="color: #000000; ">&nbsp;IsValidate</span><span style="color: #808080; ">=</span><span style="color: #800000; font-weight: bold; ">1</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #0000FF; ">select</span><span style="color: #000000; ">&nbsp;ROW_COUNT()&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;</span><span style="color: #008000; ">@IsSucc</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;</span><span style="color: #008000; ">@IsSucc</span><span style="color: #000000; ">&nbsp;</span><span style="color: #808080; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #800000; font-weight: bold; ">0</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">then</span><span style="color: #000000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">insert</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">into</span><span style="color: #000000; ">&nbsp;Tbl_MarketLimit(ItemID,LimitCount)&nbsp;</span><span style="color: #0000FF; ">values</span><span style="color: #000000; ">(inItemID,inLimitCount);<br />&nbsp;&nbsp;</span><span style="color: #0000FF; ">end</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">;<br /></span><span style="color: #0000FF; ">END</span><span style="color: #000000; ">;;<br /><br /><br /><br /></span></div><img src ="http://www.cppblog.com/API/aggbug/165641.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2012-02-15 09:35 <a href="http://www.cppblog.com/API/archive/2012/02/15/165641.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mysql表结构操作</title><link>http://www.cppblog.com/API/archive/2011/07/05/150179.html</link><dc:creator>C++技术中心</dc:creator><author>C++技术中心</author><pubDate>Tue, 05 Jul 2011 01:05:00 GMT</pubDate><guid>http://www.cppblog.com/API/archive/2011/07/05/150179.html</guid><wfw:comment>http://www.cppblog.com/API/comments/150179.html</wfw:comment><comments>http://www.cppblog.com/API/archive/2011/07/05/150179.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/API/comments/commentRss/150179.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/API/services/trackbacks/150179.html</trackback:ping><description><![CDATA[<div id="cnblogs_post_body">
<p>ALTER TABLE：添加，修改，删除表的列，约束等表的定义。</p>
<ul><li>查看列：desc 表名;</li><li>修改表名：alter table t_book rename to bbb;</li><li>添加列：alter table 表名 add column 列名 varchar(30);</li><li>删除列：alter table 表名 drop column 列名;</li><li>修改列名MySQL： alter table bbb change nnnnn hh int;</li><li>修改列名SQLServer：exec sp_rename't_student.name','nn','column';</li><li>修改列名Oracle：lter table bbb rename column nnnnn to hh int;</li><li>修改列属性：alter table t_book modify name varchar(22); </li></ul>
<p>sp_rename：SQLServer 内置的存储过程，用与修改表的定义。</p></div><img src ="http://www.cppblog.com/API/aggbug/150179.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/API/" target="_blank">C++技术中心</a> 2011-07-05 09:05 <a href="http://www.cppblog.com/API/archive/2011/07/05/150179.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>