﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-黑夜里的狼-随笔分类-MySQL</title><link>http://www.blogjava.net/hellxoul/category/50245.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 16 Jun 2014 03:57:27 GMT</lastBuildDate><pubDate>Mon, 16 Jun 2014 03:57:27 GMT</pubDate><ttl>60</ttl><item><title>数据库事务隔离级别</title><link>http://www.blogjava.net/hellxoul/archive/2014/06/15/414771.html</link><dc:creator>hellxoul</dc:creator><author>hellxoul</author><pubDate>Sun, 15 Jun 2014 07:15:00 GMT</pubDate><guid>http://www.blogjava.net/hellxoul/archive/2014/06/15/414771.html</guid><wfw:comment>http://www.blogjava.net/hellxoul/comments/414771.html</wfw:comment><comments>http://www.blogjava.net/hellxoul/archive/2014/06/15/414771.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hellxoul/comments/commentRss/414771.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hellxoul/services/trackbacks/414771.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #ffffff;"><span style="font-size: medium;">转自：</span><span style="font-family: verdana, 'courier new'; line-height: 21px;">http://singo107.iteye.com/blog/1175084</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #ffffff;"><span style="font-size: medium;">数据库事务的隔离级别有4个，由低到高依次为Read uncommitted&nbsp;、Read committed&nbsp;、Repeatable read&nbsp;、Serializable&nbsp;，这四个级别可以逐个解决脏读&nbsp;、不可重复读&nbsp;、幻读&nbsp;这几类问题。</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #ffffff;"><span style="font-size: medium;"><br /></span></p><div style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #ffffff;"><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">&#8730;: 可能出现&nbsp;&nbsp;&nbsp;&nbsp;&#215;: 不会出现</span></p><table width="90%" cellspacing="0" border="1" cellpadding="4"><tbody><tr><td style="font-size: 1em;"></td><td style="font-size: 1em;"><span style="font-size: medium;">脏读</span></td><td style="font-size: 1em;"><span style="font-size: medium;">不可重复读</span></td><td style="font-size: 1em;"><span style="font-size: medium;">幻读</span></td></tr><tr><td style="font-size: 1em;"><span style="font-size: medium;">Read uncommitted</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#8730;</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#8730;</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#8730;</span></td></tr><tr><td style="font-size: 1em;"><span style="font-size: medium;">Read committed</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#215;</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#8730;</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#8730;</span></td></tr><tr><td style="font-size: 1em;"><span style="font-size: medium;">Repeatable read</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#215;</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#215;</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#8730;</span></td></tr><tr><td style="font-size: 1em;"><span style="font-size: medium;">Serializable</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#215;</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#215;</span></td><td style="font-size: 1em;"><span style="font-size: medium;">&#215;</span></td></tr></tbody></table><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">注意：我们讨论隔离级别的场景，主要是在多个事务并发&nbsp;的情况下，因此，接下来的讲解都围绕事务并发。</span></p><h5><span style="color: #008000; font-size: medium;">Read uncommitted 读未提交</span></h5><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">公司发工资了，领导把5000元打到singo的账号上，但是该事务并未提交，而singo正好去查看账户，发现工资已经到账，是5000元整，非常高 兴。可是不幸的是，领导发现发给singo的工资金额不对，是2000元，于是迅速回滚了事务，修改金额后，将事务提交，最后singo实际的工资只有 2000元，singo空欢喜一场。</span></p><p style="margin: 0px; padding: 0px;"><br /><img src="http://dl.iteye.com/upload/attachment/556524/f244ae46-c8f4-3bc1-906e-d1d9c1af3516.gif" alt="" style="border: 0px;" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">出现上述情况，即我们所说的脏读&nbsp;，两个并发的事务，&#8220;事务A：领导给singo发工资&#8221;、&#8220;事务B：singo查询工资账户&#8221;，事务B读取了事务A尚未提交的数据。</span></p><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">当隔离级别设置为Read uncommitted&nbsp;时，就可能出现脏读，如何避免脏读，请看下一个隔离级别。</span></p><h5><span style="color: #008000; font-size: medium;">Read committed 读提交</span></h5><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">singo拿着工资卡去消费，系统读取到卡里确实有2000元，而此时她的老婆也正好在网上转账，把singo工资卡的2000元转到另一账户，并在 singo之前提交了事务，当singo扣款时，系统检查到singo的工资卡已经没有钱，扣款失败，singo十分纳闷，明明卡里有钱，为 何......</span></p><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">出现上述情况，即我们所说的不可重复读&nbsp;，两个并发的事务，&#8220;事务A：singo消费&#8221;、&#8220;事务B：singo的老婆网上转账&#8221;，事务A事先读取了数据，事务B紧接了更新了数据，并提交了事务，而事务A再次读取该数据时，数据已经发生了改变。</span></p><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">当隔离级别设置为Read committed&nbsp;时，避免了脏读，但是可能会造成不可重复读。</span></p><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">大多数数据库的默认级别就是Read committed，比如Sql Server , Oracle。如何解决不可重复读这一问题，请看下一个隔离级别。</span></p><h5><span style="color: #008000; font-size: medium;">Repeatable read 重复读</span></h5><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">当隔离级别设置为Repeatable read&nbsp;时，可以避免不可重复读。当singo拿着工资卡去消费时，一旦系统开始读取工资卡信息（即事务开始），singo的老婆就不可能对该记录进行修改，也就是singo的老婆不能在此时转账。</span></p><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">虽然Repeatable read避免了不可重复读，但还有可能出现幻读&nbsp;。</span></p><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">singo的老婆工作在银行部门，她时常通过银行内部系统查看singo的信用卡消费记录。有一天，她正在查询到singo当月信用卡的总消费金额 （select sum(amount) from transaction where month = 本月）为80元，而singo此时正好在外面胡吃海塞后在收银台买单，消费1000元，即新增了一条1000元的消费记录（insert transaction ... ），并提交了事务，随后singo的老婆将singo当月信用卡消费的明细打印到A4纸上，却发现消费总额为1080元，singo的老婆很诧异，以为出 现了幻觉，幻读就这样产生了。</span></p><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">注：Mysql的默认隔离级别就是Repeatable read。</span></p><h5><span style="color: #008000; font-size: medium;">Serializable 序列化</span></h5><p style="margin: 0px; padding: 0px;"><span style="font-size: medium;">Serializable&nbsp;是最高的事务隔离级别，同时代价也花费最高，性能很低，一般很少使用，在该级别下，事务顺序执行，不仅可以避免脏读、不可重复读，还避免了幻像读。</span></p></div><img src ="http://www.blogjava.net/hellxoul/aggbug/414771.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hellxoul/" target="_blank">hellxoul</a> 2014-06-15 15:15 <a href="http://www.blogjava.net/hellxoul/archive/2014/06/15/414771.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CentOS 6.3下MySQL 5.6源码安装</title><link>http://www.blogjava.net/hellxoul/archive/2013/05/17/399411.html</link><dc:creator>hellxoul</dc:creator><author>hellxoul</author><pubDate>Fri, 17 May 2013 07:20:00 GMT</pubDate><guid>http://www.blogjava.net/hellxoul/archive/2013/05/17/399411.html</guid><wfw:comment>http://www.blogjava.net/hellxoul/comments/399411.html</wfw:comment><comments>http://www.blogjava.net/hellxoul/archive/2013/05/17/399411.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hellxoul/comments/commentRss/399411.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hellxoul/services/trackbacks/399411.html</trackback:ping><description><![CDATA[<div>Linux操作系统：CentOS 6.3</div><div></div><div>1：下载：当前mysql版本到了5.6.10</div><div>&nbsp;&nbsp;</div><div>&nbsp;下载地址：http://dev.mysql.com/downloads/mysql/5.6.html#downloads</div><div>&nbsp;&nbsp;</div><div>&nbsp;选择&#8220;Source Code&#8221;</div><div>&nbsp;&nbsp;</div><div></div><div></div><div></div><div></div><div>在此之前最好注册一个Oracle账号</div><div>&nbsp;&nbsp;</div><div>&nbsp;2：必要软件包</div><div>yum -y install &nbsp;gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake&nbsp;</div><div></div><div>3:编译安装</div><div>[root@server182 ~]# groupadd mysql&nbsp;</div><div>[root@server182 ~]# useradd -r -g mysql mysql&nbsp;</div><div>[root@server182 ~]# tar -zxvf mysql-5.6.10.tar.gz&nbsp;</div><div>[root@server182 ~]# cd mysql-5.6.10&nbsp;</div><div>[root@server182 mysql-5.6.10]# cmake .&nbsp;</div><div>[root@server182 mysql-5.6.10]# make &amp;&amp; make install&nbsp;</div><div>-------------------------默认情况下是安装在/usr/local/mysql&nbsp;</div><div>[root@server182 ~]# chown -R mysql.mysql /usr/local/mysql&nbsp;</div><div>[root@server182 ~]# cd /usr/local/mysql/scripts&nbsp;</div><div>[root@server182 ~]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data&nbsp;</div><div>[root@server182 ~]# cd /usr/local/mysql/support-files&nbsp;</div><div>[root@server182 support-files]# cp mysql.server /etc/rc.d/init.d/mysql&nbsp;</div><div>[root@server182 support-files]# cp my-default.cnf /etc/my.cnf&nbsp;</div><div>[root@server182 ~]# chkconfig -add mysql&nbsp;</div><div>[root@server182 ~]# chkconfig mysql on&nbsp;</div><div>[root@server182 ~]# service mysql start&nbsp;</div><div>Starting MySQL SUCCESS! &nbsp;</div><div>[root@server182 support-files]# mysql&nbsp;</div><div>Welcome to the MySQL monitor. &nbsp;Commands end with ; or \g.&nbsp;</div><div>Your MySQL connection id is 1&nbsp;</div><div>Server version: 5.6.10 Source distribution&nbsp;</div><div>Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.&nbsp;</div><div>&nbsp;&nbsp;</div><div>Oracle is a registered trademark of Oracle Corporation and/or its&nbsp;</div><div>affiliates. Other names may be trademarks of their respective&nbsp;</div><div>owners.&nbsp;</div><div>Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.&nbsp;</div><div>&nbsp;</div><div>mysql&gt; &nbsp;</div><div>mysql&gt; status;&nbsp;</div><div>--------------&nbsp;</div><div>mysql &nbsp;Ver 14.14 Distrib 5.6.10, for Linux (i686) using &nbsp;EditLine wrapper&nbsp;</div><div>Connection id: &nbsp;1&nbsp;</div><div>Current database: &nbsp;</div><div>Current user: &nbsp;root@localhost&nbsp;</div><div>SSL: &nbsp; &nbsp;Not in use&nbsp;</div><div>Current pager: &nbsp;stdout&nbsp;</div><div>Using outfile: &nbsp;''&nbsp;</div><div>Using delimiter: &nbsp;;&nbsp;</div><div>Server version: &nbsp;5.6.10 Source distribution&nbsp;</div><div>Protocol version: &nbsp;10&nbsp;</div><div>Connection: &nbsp;Localhost via UNIX socket&nbsp;</div><div>Server characterset: &nbsp;utf8&nbsp;</div><div>Db &nbsp; &nbsp;characterset: &nbsp;utf8&nbsp;</div><div>Client characterset: &nbsp;utf8&nbsp;</div><div>Conn. &nbsp;characterset: &nbsp;utf8&nbsp;</div><div>UNIX socket: &nbsp;/tmp/mysql.sock&nbsp;</div><div>Uptime: &nbsp; &nbsp;5 min 45 sec&nbsp;</div><div>&nbsp;&nbsp;</div><div>Threads: 1 &nbsp;Questions: 5 &nbsp;Slow queries: 0 &nbsp;Opens: 70 &nbsp;Flush tables: 1 &nbsp;Open tables: 63 &nbsp;Queries per second avg: 0.014&nbsp;</div><div>-------------&nbsp;</div><div>mysql&gt; &nbsp;</div><div></div><div>安装完毕。</div><div></div><div>原文链接：http://www.linuxidc.com/Linux/2013-02/79791.htm</div><img src ="http://www.blogjava.net/hellxoul/aggbug/399411.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hellxoul/" target="_blank">hellxoul</a> 2013-05-17 15:20 <a href="http://www.blogjava.net/hellxoul/archive/2013/05/17/399411.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CentOS 6.3/6.4 Minimal 源码安装 MySQL 5.6.10/5.6.11</title><link>http://www.blogjava.net/hellxoul/archive/2013/05/17/399410.html</link><dc:creator>hellxoul</dc:creator><author>hellxoul</author><pubDate>Fri, 17 May 2013 07:18:00 GMT</pubDate><guid>http://www.blogjava.net/hellxoul/archive/2013/05/17/399410.html</guid><wfw:comment>http://www.blogjava.net/hellxoul/comments/399410.html</wfw:comment><comments>http://www.blogjava.net/hellxoul/archive/2013/05/17/399410.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hellxoul/comments/commentRss/399410.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hellxoul/services/trackbacks/399410.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12px;">MySQL 5.6正式版发布了，相对于5.5版本作出了不少改进，其源码安装配置方式也有所变化，本文根据实际操作，不断尝试，精确还原了安装的具体步骤。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">环境：CentOS 6.3/6.4 最小化缺省安装，配置好网卡。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">安装MySQL前，确认Internet连接正常，以便下载安装文件。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">先使用 yum -y update 指令升级系统到最新版本。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">本安装将MySQL的数据文件与执行文件分离，如果你打算设置到不同的路径，注意修改对应的执行命令和数据库初始化脚本。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 修改防火墙设置，打开3306端口</span></div><div><span style="font-size: 12px;">vi /etc/sysconfig/iptables</span></div><div><span style="font-size: 12px;">-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 重启防火墙使新设置生效</span></div><div><span style="font-size: 12px;">service iptables restart</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 新增用户组</span></div><div><span style="font-size: 12px;">groupadd mysql</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 新增用户</span></div><div><span style="font-size: 12px;">useradd mysql -g mysql</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 新建数据库执行文件目录</span></div><div><span style="font-size: 12px;">mkdir -p /usr/local/mysql</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 新建数据库数据文件目录</span></div><div><span style="font-size: 12px;">mkdir -p /db/mysql/data</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 编辑PATH搜索路径</span></div><div><span style="font-size: 12px;">vi /etc/profile</span></div><div><span style="font-size: 12px;">Append these 2 lines to the end of the file:</span></div><div><span style="font-size: 12px;">PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH</span></div><div><span style="font-size: 12px;">export PATH</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 生效PATH搜索路径</span></div><div><span style="font-size: 12px;">source /etc/profile</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 编辑hosts文件，加入本机IP和主机名</span></div><div><span style="font-size: 12px;">vi /etc/hosts</span></div><div><span style="font-size: 12px;">192.168.211.100 &nbsp; &nbsp; &nbsp;centhost.centdomain</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 安装编译源码所需的工具和库</span></div><div><span style="font-size: 12px;">yum -y install wget gcc-c++ ncurses-devel cmake make perl</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 进入源码压缩包下载目录</span></div><div><span style="font-size: 12px;">cd /usr/local/src</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 下载源码压缩包，下载包34M大小，有点慢，等吧。</span></div><div><span style="font-size: 12px;">wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.10.tar.gz/from/http://cdn.mysql.com/</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 解压缩源码包</span></div><div><span style="font-size: 12px;">tar -zxvf mysql-5.6.10.tar.gz</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 进入解压缩源码目录</span></div><div><span style="font-size: 12px;">cd mysql-5.6.10</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 从mysql5.5起，mysql源码安装开始使用cmake了，执行源码编译配置脚本。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">cmake \</span></div><div><span style="font-size: 12px;">-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \</span></div><div><span style="font-size: 12px;">-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \</span></div><div><span style="font-size: 12px;">-DDEFAULT_CHARSET=utf8 \</span></div><div><span style="font-size: 12px;">-DDEFAULT_COLLATION=utf8_general_ci \</span></div><div><span style="font-size: 12px;">-DWITH_MYISAM_STORAGE_ENGINE=1 \</span></div><div><span style="font-size: 12px;">-DWITH_INNOBASE_STORAGE_ENGINE=1 \</span></div><div><span style="font-size: 12px;">-DWITH_ARCHIVE_STORAGE_ENGINE=1 \</span></div><div><span style="font-size: 12px;">-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \</span></div><div><span style="font-size: 12px;">-DWITH_MEMORY_STORAGE_ENGINE=1 \</span></div><div><span style="font-size: 12px;">-DWITH_READLINE=1 \</span></div><div><span style="font-size: 12px;">-DENABLED_LOCAL_INFILE=1 \</span></div><div><span style="font-size: 12px;">-DMYSQL_DATADIR=/db/mysql/data \</span></div><div><span style="font-size: 12px;">-DMYSQL_USER=mysql \</span></div><div><span style="font-size: 12px;">-DMYSQL_TCP_PORT=3306</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 编译源码，这一步时间会较长，耐心等待。</span></div><div><span style="font-size: 12px;">make</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 安装</span></div><div><span style="font-size: 12px;">make install</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 清除安装临时文件</span></div><div><span style="font-size: 12px;">make clean</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 修改目录拥有者</span></div><div><span style="font-size: 12px;">chown -R mysql:mysql /usr/local/mysql</span></div><div><span style="font-size: 12px;">chown -R mysql:mysql /db/mysql/data</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 进入安装路径</span></div><div><span style="font-size: 12px;">cd /usr/local/mysql</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 执行初始化配置脚本，创建系统自带的数据库和表。</span></div><div><span style="font-size: 12px;">scripts/mysql_install_db --user=mysql --datadir=/db/mysql/data</span></div><div><span style="font-size: 12px;">初始化脚本在 /usr/local/mysql/my.cnf 生成了配置文件。需要更改该配置文件的所有者：</span></div><div><span style="font-size: 12px;">chown -R mysql:mysql /usr/local/mysql</span></div><div><span style="font-size: 12px;">多说两句：在启动MySQL服务时，会按照一定次序搜索my.cnf，先在/etc目录下找，找不到则会搜索"$basedir/my.cnf"，在本例中就是 /usr/local/mysql/my.cnf，这是新版MySQL的配置文件的默认位置！注意：在CentOS 6.4版操作系统的最小安装完成后，在/etc目录下会存在一个my.cnf，需要将此文件更名为其他的名字，如：/etc/my.cnf.bak，否则，该文件会干扰源码安装的MySQL的正确配置，造成无法启动。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 复制服务启动脚本</span></div><div><span style="font-size: 12px;">cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">＃ 启动MySQL服务</span></div><div><span style="font-size: 12px;">service mysql start</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"># 设置开机自动启动服务</span></div><div><span style="font-size: 12px;">chkconfig mysql on</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"># 修改MySQL用户root的密码</span></div><div><span style="font-size: 12px;">mysql -u root</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">mysql&gt;use mysql;</span></div><div><span style="font-size: 12px;">mysql&gt;GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";</span></div><div><span style="font-size: 12px;">mysql&gt;update user set Password = password('123456') where User='root';</span></div><div><span style="font-size: 12px;">mysql&gt;flush privileges;</span></div><div><span style="font-size: 12px;">mysql&gt;exit;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"># 可选：运行安全设置脚本，修改MySQL用户root（不是系统的root!）的密码，禁止root远程连接（防止破解密码），移除test数据库和匿名用户，强烈建议生产服务器使用：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">/usr/local/mysql/bin/mysql_secure_installation</span></div><div><span style="font-size: 12px;"><br /></span></div><div>&nbsp;</div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">后记：</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">2013年3月18日更新：</span></div><div><span style="font-size: 12px;">如果要使Windows平台下的MySQL和Linux平台下的MySQL协同工作，你需要设置Linux平台下的全局变量lower_case_table_names=1，强制将数据表名称转换为小写（大小写不敏感）。参考我另一篇博文：http://www.cnblogs.com/jlzhou/archive/2013/03/18/2966106.html</span></div><div><span style="font-size: 12px;"><br /></span></div><div>&nbsp;</div><div><span style="font-size: 12px;"><br /></span></div><div>&nbsp;</div><div><span style="font-size: 12px;">&gt;&gt;&gt;&gt;&gt; 版权没有 &gt;&gt;&gt;&gt;&gt; 欢迎转载 &gt;&gt;&gt;&gt;&gt; 原文地址 &gt;&gt;&gt;&gt;&gt; http://www.cnblogs.com/jlzhou &gt;&gt;&gt;&gt;&gt; 雄鹰在鸡窝里长大，就会失去飞翔的本领，野狼在羊群里成长，也会爱上羊而丧失狼性。人生的奥妙就在于与人相处。生活的美好则在于送人玫瑰。和聪明的人在一起,你才会更加睿智。和优秀的人在一起，你才会出类拔萃。所以，你是谁并不重要，重要的是，你和谁在一起。</span></div><img src ="http://www.blogjava.net/hellxoul/aggbug/399410.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hellxoul/" target="_blank">hellxoul</a> 2013-05-17 15:18 <a href="http://www.blogjava.net/hellxoul/archive/2013/05/17/399410.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CentOS6.3安装MySQL5.6</title><link>http://www.blogjava.net/hellxoul/archive/2013/02/24/395639.html</link><dc:creator>hellxoul</dc:creator><author>hellxoul</author><pubDate>Sat, 23 Feb 2013 16:31:00 GMT</pubDate><guid>http://www.blogjava.net/hellxoul/archive/2013/02/24/395639.html</guid><wfw:comment>http://www.blogjava.net/hellxoul/comments/395639.html</wfw:comment><comments>http://www.blogjava.net/hellxoul/archive/2013/02/24/395639.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hellxoul/comments/commentRss/395639.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hellxoul/services/trackbacks/395639.html</trackback:ping><description><![CDATA[1.下载MySQL<br />
我下载的版本：mysql-5.5.22.tar.gz<br />
<br />
2.安装之前先卸载CentOS自带的MySQL<br />
[root@localhost ~]# yum remove mysql<br />
<br />
3.编译安装Cmake<br />
下载cmake源码包：http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz<br />
<br />
从共享目录移至usr目录<br />
[root@localhost ~]# mv /mnt/hgfs/Share-CentOS/cmake-2.8.4.tar.gz /usr/cmake-2.8.4.tar.gz<br />
[root@localhost ~]# cd /usr<br />
<br />
解压并安装cmake<br />
[root@localhost usr]# tar xzvf cmake-2.8.4.tar.gz<br />
[root@localhost usr]# cd cmake-2.8.4<br />
[root@localhost cmake-2.8.4]# ./bootstrap<br />
<br />
---------------------------------------------<br />
CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.<br />
---------------------------------------------<br />
Error when bootstrapping CMake:<br />
Cannot find appropriate C compiler on this system.<br />
Please specify one using environment variable CC.<br />
See cmake_bootstrap.log for compilers attempted.<br />
<br />
---------------------------------------------<br />
Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log<br />
---------------------------------------------<br />
报错：缺少C的编译器<br />
解决办法：安装gcc编译器<br />
[root@localhost ~]# yum install gcc<br />
<br />
继续安装Cmake<br />
[root@localhost cmake-2.8.4]# ./bootstrap <br />
<br />
---------------------------------------------<br />
CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.<br />
C compiler on this system is: cc<br />
---------------------------------------------<br />
Error when bootstrapping CMake:<br />
Cannot find appropriate C++ compiler on this system.<br />
Please specify one using environment variable CXX.<br />
See cmake_bootstrap.log for compilers attempted.<br />
---------------------------------------------<br />
Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log<br />
---------------------------------------------<br />
报错：缺少C++编译器 <br />
解决办法：安装gcc-c++编译器<br />
[root@localhost ~]# yum install gcc-c++<br />
<br />
再次安装<br />
[root@localhost cmake-2.8.4]# ./bootstrap <br />
没有报错，编译安装<br />
[root@localhost cmake-2.8.4]# gmake<br />
[root@localhost cmake-2.8.4]# gmake install<br />
<br />
4.正式开始安装MySQL<br />
添加MySQL用户和用户组<br />
[root@localhost ~]# groupadd mysql<br />
[root@localhost ~]# useradd -g mysql mysql<br />
<br />
MySQL源码包从共享文件夹移至/usr并解压<br />
[root@localhost ~]mv /mnt/hgfs/Share-CentOS/mysql-5.5.22.tar.gz /usr/mysql-5.5.22.tar.gz<br />
[root@localhost usr]# tar xzvf mysql-5.5.22.tar.gz<br />
[root@localhost usr]# cd mysql-5.5.22<br />
<br />
Cmake运行<br />
[root@localhost mysql-5.5.22]# cmake .<br />
<br />
开始编译安装<br />
[root@localhost mysql-5.5.22]# make &amp;&amp; make install<br />
<br />
进入安装目录，将程序二进制的所有权改为root，数据目录的说有权改为mysql用户，更新授权表<br />
[root@localhost mysql-5.5.22]# cd /usr/local/mysql/<br />
[root@localhost mysql]# chown -R root .<br />
[root@localhost mysql]# chown -R mysql .<br />
[root@localhost mysql]# chgrp -R mysql .<br />
[root@localhost mysql]# scripts/mysql_install_db --user=mysql<br />
<br />
安全启动MySQL(默认密码为空)<br />
[root@localhost mysql]#./bin/mysqld_safe --user=mysql&amp;<br />
<br />
报错： <br />
<br />
120908 00:16:25 mysqld_safe Logging to '/usr/local/mysql/data/CentOS.err'.<br />
120908 00:16:26 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data<br />
<br />
解决方法：<br />
[root@CentOS ~]# cd /usr/local/mysql/data<br />
<br />
[root@CentOS data]# ls -l<br />
总用量 29744<br />
-rw-rw----  1 mysql root      1585 9月   8 00:16 CentOS.err<br />
-rw-rw----  1 mysql mysql        6 9月   8 00:16 CentOS.pid<br />
-rw-rw----  1 mysql mysql 18874368 9月   8 00:16 ibdata1<br />
-rw-rw----  1 mysql mysql  5242880 9月   8 00:16 ib_logfile0<br />
-rw-rw----  1 mysql mysql  5242880 9月   8 00:16 ib_logfile1<br />
drwxr-xr-x  2 mysql mysql     4096 9月   8 00:14 mysql<br />
-rw-rw----  1 mysql mysql    27293 9月   8 00:14 mysql-bin.000001<br />
-rw-rw----  1 mysql mysql  1031892 9月   8 00:14 mysql-bin.000002<br />
-rw-rw----  1 mysql mysql      107 9月   8 00:16 mysql-bin.000003<br />
-rw-rw----  1 mysql mysql       57 9月   8 00:16 mysql-bin.index<br />
drwx------  2 mysql mysql     4096 9月   8 00:14 performance_schema<br />
drwxr-xr-x  2 mysql mysql     4096 9月   8 00:08 test<br />
[root@CentOS data]# chgrp -R mysql CentOS.err<br />
[root@CentOS data]# ls -l<br />
总用量 29736<br />
-rw-rw---- 1 mysql mysql     1585 9月   8 00:16 CentOS.err<br />
-rw-rw---- 1 mysql mysql        6 9月   8 00:16 CentOS.pid<br />
-rw-rw---- 1 mysql mysql 18874368 9月   8 00:16 ibdata1<br />
-rw-rw---- 1 mysql mysql  5242880 9月   8 00:16 ib_logfile0<br />
-rw-rw---- 1 mysql mysql  5242880 9月   8 00:16 ib_logfile1<br />
drwxr-xr-x 2 mysql mysql     4096 9月   8 00:14 mysql<br />
-rw-rw---- 1 mysql mysql    27293 9月   8 00:14 mysql-bin.000001<br />
-rw-rw---- 1 mysql mysql  1031892 9月   8 00:14 mysql-bin.000002<br />
-rw-rw---- 1 mysql mysql      107 9月   8 00:16 mysql-bin.000003<br />
-rw-rw---- 1 mysql mysql       57 9月   8 00:16 mysql-bin.index<br />
drwx------ 2 mysql mysql     4096 9月   8 00:14 performance_schema<br />
drwxr-xr-x 2 mysql mysql     4096 9月   8 00:08 test<br />
<br />
连接本机MySQL<br />
[root@localhost mysql]#mysql &#8211;u root &#8211;p<br />
提示输入password，默认为空，按Enter即可<br />
<br />
断开连接<br />
mysql&gt;exit;<br />
<br />
为root账户设置密码<br />
[root@localhost ~]# cd /usr/local/mysql/bin<br />
[root@localhost mysql]# ./bin/mysqladmin -u root password 123456<br />
Enter Password:123456<br />
<br />
设置选项文件，将配置文件拷贝到/etc下<br />
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/mysql.cnf<br />
<br />
设置开机自启动<br />
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql<br />
[root@localhost mysql]# chmod +x /etc/init.d/mysql
<p>[root@localhost mysql]# chkconfig mysql on<br />
&nbsp;<br />
</p>
<br />
通过服务来启动和关闭Mysql<br />
[root@localhost ~]# service mysql start<br />
[root@localhost ~]# service mysql stop<br />
<br />
5.安装设置完毕，之后使用只需启动-连接-断开-关闭，命令如下：<br />
[root@CentOS mysql]# service mysql start<br />
Starting MySQL..                                           [确定]<br />
[root@CentOS mysql]# mysql -u root -p<br />
Enter password:<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 1<br />
Server version: 5.5.22 Source distribution<br />
<br />
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.<br />
<br />
Oracle is a registered trademark of Oracle Corporation and/or its<br />
affiliates. Other names may be trademarks of their respective<br />
owners.<br />
<br />
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.<br />
<br />
mysql&gt; show databases;<br />
+--------------------+<br />
| Database           |<br />
+--------------------+<br />
| information_schema |<br />
| mysql              |<br />
| performance_schema |<br />
| test               |<br />
+--------------------+<br />
4 rows in set (0.07 sec)<br />
<br />
mysql&gt; exit;<br />
Bye<br />
[root@CentOS mysql]# service mysql stop<br />
Shutting down MySQL.                                       [确定]<br />
<br />
6.其它：<br />
查看进程命令 ps &#8211;ef|grep mysqld<br />
kill进程命令 kill &#8211;9 进程号
<img src ="http://www.blogjava.net/hellxoul/aggbug/395639.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hellxoul/" target="_blank">hellxoul</a> 2013-02-24 00:31 <a href="http://www.blogjava.net/hellxoul/archive/2013/02/24/395639.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>