﻿<?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-himalayas-随笔分类-database</title><link>http://www.blogjava.net/himalayas/category/50231.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 10 Feb 2013 01:59:05 GMT</lastBuildDate><pubDate>Sun, 10 Feb 2013 01:59:05 GMT</pubDate><ttl>60</ttl><item><title>mysql 5.5.19 主从配置+读写分离</title><link>http://www.blogjava.net/himalayas/archive/2012/01/10/368205.html</link><dc:creator>himalayas</dc:creator><author>himalayas</author><pubDate>Tue, 10 Jan 2012 06:00:00 GMT</pubDate><guid>http://www.blogjava.net/himalayas/archive/2012/01/10/368205.html</guid><wfw:comment>http://www.blogjava.net/himalayas/comments/368205.html</wfw:comment><comments>http://www.blogjava.net/himalayas/archive/2012/01/10/368205.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/himalayas/comments/commentRss/368205.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/himalayas/services/trackbacks/368205.html</trackback:ping><description><![CDATA[<div><div><span style="color: #00ff00; ">master:10.13.120.236</span></div><div><span style="color: #00ff00; ">slave:10.13.120.233</span></div><div><span style="color: #ff0000; ">步骤一：安装master</span></div><div>下载mysql-5.1.60-linux-x86_64-glibc23.tar.gz&nbsp;放到/home/a/soft/下</div><div>shell&gt;sudo groupadd mysql&nbsp;</div><div>shell&gt;sudo useradd -r -g mysql mysql&nbsp;</div><div>shell&gt;cd /home/a/soft/&nbsp;</div><div>shell&gt;tar zxvf mysql-5.1.60-linux-x86_64-glibc23.tar.gz</div><div>shell&gt;cd /usr/local/&nbsp;</div><div>shell&gt;sudo ln -s /home/a/soft/mysql-5.1.60-linux-x86_64-glibc23 mysql&nbsp;</div><div>shell&gt; cd mysql&nbsp;</div><div>shell&gt;sudo chown -R mysql .&nbsp;</div><div>shell&gt;sudo chgrp -R mysql .&nbsp;</div><div>shell&gt;sudo scripts/mysql_install_db --user=mysql&nbsp;</div><div>shell&gt;sudo chown -R root .&nbsp;</div><div>shell&gt;sudo chown -R mysql data&nbsp;</div><div># Next command is optional&nbsp;</div><div>shell&gt;sudo cp support-files/my-medium.cnf /etc/my.cnf&nbsp;</div><div>shell&gt;sudo bin/mysqld_safe --user=mysql &amp;&nbsp;</div><div># Next command is optional&nbsp;</div><div>shell&gt;sudo cp support-files/mysql.server /etc/init.d/mysql.server</div><div></div><div>#配置my.cnf</div><div>####################################</div><div>binlog-do-db=phpdb</div><div>binlog-ignore-db=mysql</div><div>log-bin=/usr/local/mysql/log/updatelog</div><div>log-slave-updates</div><div>slave-skip-errors=all</div><div>#####################################</div><div></div><div>$sudo service mysql.server start</div><div>$mysql -uroot -p</div><div>改变当前数据库为mysql：</div><div>mysql&gt;use mysql</div><div>设置从本地主机登录的root帐号密码：</div><div>mysql&gt;set password for root@localhost=password('root');</div><div>删除匿名帐号：&nbsp;</div><div>mysql&gt;delete from user where user='';</div><div>删除密码为空的帐号：</div><div>mysql&gt;delete from user where password='';</div><div>删除允许非localhost主机登录的帐号：</div><div>mysql&gt;delete from user where host&lt;&gt;'localhost';</div><div>执行下面的命令使更改生效：</div><div>mysql&gt;flush privileges;&nbsp;</div><div>mysql&gt;update user set host = '%' where user = 'root';</div><div>mysql&gt;create database phpdb;</div><div>mysql&gt;use phpdb;</div><div>mysql&gt;create table person(id int(10) primary key auto_increment,name varchar(100) not null);</div><div>#dump主库数据</div><div>mysql&gt;flush tables with read lock;</div><div>$mysqldump -h127.0.0.1 -p3306 -uroot -p phpdb &gt; /mnt/phpdb.sql&nbsp;</div><div>（/mnt目录是我自己做的NFS，就是方便不同机器间使用文件，不用nfs也可以）</div><div>mysql&gt; unlock tables;</div><div>mysql&gt;use mysql</div><div>mysql&gt;GRANT REPLICATION SLAVE ON *.* TO 'slave1_user'@'10.13.120.233' IDENTIFIED BY 'root';</div><div></div><div>$sudo service mysql.server restart</div><div>mysql&gt; show master status;</div><div>+------------------+----------+--------------+------------------+</div><div>| File &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Position | Binlog_Do_DB | Binlog_Ignore_DB |</div><div>+------------------+----------+--------------+------------------+</div><div>| mysql-bin.000006 | &nbsp; &nbsp; 2366 | phpdb &nbsp; &nbsp; &nbsp; &nbsp;| mysql &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div><div>+------------------+----------+--------------+------------------+</div><div>1 row in set (0.00 sec)</div><div><br /><span style="color: #ff0000; ">步骤二：安装slave</span></div><div></div><div>下载mysql-5.1.60-linux-x86_64-glibc23.tar.gz&nbsp;放到/home/a/soft/下</div><div>shell&gt;sudo groupadd mysql&nbsp;</div><div>shell&gt;sudo useradd -r -g mysql mysql&nbsp;</div><div>shell&gt;cd /home/a/soft/&nbsp;</div><div>shell&gt;tar zxvf mysql-5.1.60-linux-x86_64-glibc23.tar.gz</div><div>shell&gt;cd /usr/local/&nbsp;</div><div>shell&gt;sudo ln -s /home/a/soft/mysql-5.1.60-linux-x86_64-glibc23 mysql&nbsp;</div><div>shell&gt; cd mysql&nbsp;</div><div>shell&gt;sudo chown -R mysql .&nbsp;</div><div>shell&gt;sudo chgrp -R mysql .&nbsp;</div><div>shell&gt;sudo scripts/mysql_install_db --user=mysql&nbsp;</div><div>shell&gt;sudo chown -R root .&nbsp;</div><div>shell&gt;sudo chown -R mysql data&nbsp;</div><div># Next command is optional&nbsp;</div><div>shell&gt;sudo cp support-files/my-medium.cnf /etc/my.cnf&nbsp;</div><div>shell&gt;sudo bin/mysqld_safe --user=mysql &amp;&nbsp;</div><div># Next command is optional&nbsp;</div><div>shell&gt;sudo cp support-files/mysql.server /etc/init.d/mysql.server</div><div></div><div>#配置my.cnf</div><div>#####################################################</div><div>server-id &nbsp; &nbsp; &nbsp; = 2</div><div>#master-host &nbsp; &nbsp; = &nbsp; mysql_master</div><div>#master-user &nbsp; &nbsp; = &nbsp; slave1_user</div><div>#master-password = &nbsp; root</div><div>#master-port &nbsp; &nbsp; = 3306</div><div>#master-connect-retry=60</div><div>replicate-ignore-db=mysql</div><div>replicate-do-db=phpdb</div><div>log-slave-update</div><div>slave-skip-errors=all</div><div>#####################################################</div><div></div><div>$sudo service mysql.server start</div><div>$mysql -uroot -p</div><div>改变当前数据库为mysql：</div><div>mysql&gt;use mysql</div><div>设置从本地主机登录的root帐号密码：</div><div>mysql&gt;set password for root@localhost=password('root');</div><div>删除匿名帐号：&nbsp;</div><div>mysql&gt;delete from user where user='';</div><div>删除密码为空的帐号：</div><div>mysql&gt;delete from user where password='';</div><div>删除允许非localhost主机登录的帐号：</div><div>mysql&gt;delete from user where host&lt;&gt;'localhost';</div><div>执行下面的命令使更改生效：</div><div>mysql&gt;flush privileges;&nbsp;</div><div>mysql&gt;update user set host = '%' where user = 'root';</div><div>mysql&gt;create database phpdb;</div><div>mysql&gt;use phpdb;</div><div></div><div>$mysqldump -h127.0.0.1 -p3306 -uroot -p phpdb &lt; /mnt/phpdb.sql &nbsp; <br />（mysql&gt;source /mnt/phpdb.sql）</div><div>mysql&gt;change master to master_host='10.13.120.236',&nbsp;</div><div>mysql&gt;master_user='slave1_user',&nbsp;</div><div>mysql&gt;master_password='root',</div><div>mysql&gt;master_port=3306,</div><div>mysql&gt;master_connect_retry=60,</div><div>mysql&gt;MASTER_LOG_FILE='mysql-bin.000006',</div><div>mysql&gt;MASTER_LOG_POS=107;</div><div></div><div>mysql&gt;slave start;</div><div></div><div>mysql&gt; show slave status\G;</div><div>*************************** 1. row ***************************</div><div>Slave_IO_State: Waiting for master to send event</div><div>Master_Host: 10.13.120.236</div><div>Master_User: slave1_user</div><div>Master_Port: 3306</div><div>Connect_Retry: 60</div><div><span style="color: #ff0000; ">Master_Log_File: mysql-bin.000006</span></div><div><span style="color: #ff0000; ">Read_Master_Log_Pos: 2366</span></div><div>Relay_Log_File: canggu-OptiPlex-760-relay-bin.000002</div><div>Relay_Log_Pos: 2512</div><div>Relay_Master_Log_File: mysql-bin.000006</div><div><span style="color: #ff0000; ">Slave_IO_Running: Yes</span></div><div><span style="color: #ff0000; ">Slave_SQL_Running: Yes</span></div><div>Replicate_Do_DB: phpdb</div><div>Replicate_Ignore_DB: mysql</div><div>Replicate_Do_Table:&nbsp;</div><div>Replicate_Ignore_Table:&nbsp;</div><div>Replicate_Wild_Do_Table:&nbsp;</div><div>Replicate_Wild_Ignore_Table:&nbsp;</div><div>Last_Errno: 0</div><div>Last_Error:&nbsp;</div><div>Skip_Counter: 0</div><div>Exec_Master_Log_Pos: 2366</div><div>Relay_Log_Space: 2682</div><div>Until_Condition: None</div><div>Until_Log_File:&nbsp;</div><div>Until_Log_Pos: 0</div><div>Master_SSL_Allowed: No</div><div>Master_SSL_CA_File:&nbsp;</div><div>Master_SSL_CA_Path:&nbsp;</div><div>Master_SSL_Cert:&nbsp;</div><div>Master_SSL_Cipher:&nbsp;</div><div>Master_SSL_Key:&nbsp;</div><div>Seconds_Behind_Master: 0</div><div>Master_SSL_Verify_Server_Cert: No</div><div>Last_IO_Errno: 0</div><div>Last_IO_Error:&nbsp;</div><div>Last_SQL_Errno: 0</div><div>Last_SQL_Error:&nbsp;</div><div>Replicate_Ignore_Server_Ids:&nbsp;</div><div><span style="color: #ff0000; ">Master_Server_Id: 1</span></div><div>1 row in set (0.00 sec)</div><div></div><div>ERROR:&nbsp;</div><div>No query specified<br /><br /></div><div>mysql&gt;slave stop;</div><div>mysql&gt;change master to master_host='10.13.120.236',&nbsp;</div><div>master_user='slave1_user',&nbsp;<br />master_password='root',<br />master_port=3306,<br />master_connect_retry=60,<br /><span style="color: #ff0000; ">MASTER_LOG_FILE='mysql-bin.000006',<br /></span><span style="color: #ff0000; ">MASTER_LOG_POS=107;</span></div><div><span style="color: #ff0000; "><br /><br />配置读写分离<br /><br />下载</span>mysql-proxy-0.8.2-linux-glibc2.3-x86-32bit.tar.gz<span style="color: #ff0000; "><br /></span><span style="color: #ff0000; ">解压并cp到/usr/local/mysql-proxy<br />在</span>/usr/local/mysql-proxy/bin下创建文件mysql-proxy.cnf添加如下内容：<br />[mysql-proxy]<div><div>daemon=true</div><div>admin-address=127.0.0.1:4041</div><div>proxy-address=:3306</div><div>admin-username=admin</div><div>admin-password=admin</div><div>admin-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/admin-sql.lua</div><div>proxy-read-only-backend-addresses=10.13.120.233:3306</div><div>proxy-backend-addresses=10.13.120.236:3306</div><div>proxy-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua</div><div>log-file=/usr/local/mysql-proxy/logs/log-debug.log</div><div>log-level=debug</div></div><div><br /><br />启动代理：<br />/usr/local/mysql-proxy/bin/mysql-proxy &nbsp;--daemon&nbsp;--defaults-file=mysql-proxy.cnf</div><span style="color: #ff0000; "><br /><br /><br /><br /></span></div></div><img src ="http://www.blogjava.net/himalayas/aggbug/368205.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/himalayas/" target="_blank">himalayas</a> 2012-01-10 14:00 <a href="http://www.blogjava.net/himalayas/archive/2012/01/10/368205.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql-5.1.60-linux-x86_64-glibc23  安装</title><link>http://www.blogjava.net/himalayas/archive/2012/01/01/367700.html</link><dc:creator>himalayas</dc:creator><author>himalayas</author><pubDate>Sun, 01 Jan 2012 08:02:00 GMT</pubDate><guid>http://www.blogjava.net/himalayas/archive/2012/01/01/367700.html</guid><wfw:comment>http://www.blogjava.net/himalayas/comments/367700.html</wfw:comment><comments>http://www.blogjava.net/himalayas/archive/2012/01/01/367700.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/himalayas/comments/commentRss/367700.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/himalayas/services/trackbacks/367700.html</trackback:ping><description><![CDATA[<div><pre style="margin-top: 0px; margin-bottom: 0px; padding: 2px; border-width: 0px; outline: 0px; font-size: 13px; vertical-align: baseline; font-family: 'Courier New', Courier, fixed, monospace; max-width: 720px; line-height: 20px; background-color: #ffffff;">下载<strong style="background-color: transparent; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; "><strong style="background-color: transparent; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; "><div style="display: inline !important; ">mysql-5.1.60-linux-x86_64-glibc23</div></code></strong><strong style="background-color: transparent; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">.tar.gz放到<strong style="background-color: transparent; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; "><em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">/home/a/soft/下</code></em></code></strong><br /></code></strong></code></strong>shell&gt;sudo <strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">groupadd mysql</code></strong> <br />shell&gt;sudo <strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">useradd -r -g mysql mysql</code></strong> <br />shell&gt;<strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">cd </code></strong><strong style="background-color: transparent; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; "><em style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">/home/a/soft/</code></em></code></strong> <br />shell&gt;<strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">tar zxvf <strong style="background-color: transparent; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; "><div style="display: inline !important; ">mysql-5.1.60-linux-x86_64-glibc23</div></code></strong><strong style="background-color: transparent; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">.tar.gz<br /></code></strong><strong style="background-color: transparent; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; "><div style="display: inline !important; "><pre style="font-weight: normal; margin-top: 0px; margin-bottom: 0px; padding-top: 2px; padding-right: 2px; padding-bottom: 2px; padding-left: 2px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-family: 'Courier New', Courier, fixed, monospace; max-width: 720px; display: inline !important; ">shell&gt;cd /usr/local/</pre></div></code></strong><span style="font-size: 13px; "> </span><br /></code></strong>shell&gt;sudo <strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">ln -s <em>/home/a/soft/</em><strong style="background-color: transparent; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; "><div style="display: inline !important; "><strong style="background-color: transparent; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; "><strong style="background-color: transparent; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; "><div style="display: inline !important; ">mysql-5.1.60-linux-x86_64-glibc23</div></code></strong><strong style="background-color: transparent; font-size: 13px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; "> mysql</code></strong><span style="font-size: 13px; "> <br /></span></code></strong></div></code></strong></code></strong>shell&gt; <strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">cd mysql</code></strong> <br />shell&gt;sudo <strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; background-color: inherit; ">chown -R mysql .</code></strong> <br />shell&gt;sudo <strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-weight: bold; background-color: transparent; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; background-color: inherit; ">chgrp -R mysql .</code></strong> <br />shell&gt;sudo <strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">scripts/mysql_install_db --user=mysql</code></strong> <br />shell&gt;sudo <strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">chown -R root .</code></strong> <br />shell&gt;sudo <strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">chown -R mysql data</code></strong> <br />shell&gt;sudo <strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; font-weight: bold; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">cp support-files/my-medium.cnf /etc/my.cnf</code></strong> <br />#配置/etc/my.cnf<br />     ......<br /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; white-space: normal;">shell&gt;sudo <strong>./scripts/mysql_install_db --user=mysql</strong></span><br />shell&gt;sudo <strong style="margin: 0px; padding: 0px; border-width: 0px; outline: 0px; vertical-align: baseline; font-weight: bold; background-color: transparent;"><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; color: inherit; font-family: 'Courier New', Courier, fixed, monospace; ">cp support-files/mysql.server /etc/init.d/mysql.server<br />$sudo service mysql.server start<br /><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">$mysql -uroot -p</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">改变当前数据库为mysql：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">mysql&gt;use mysql</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">设置从本地主机登录的root帐号密码：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">mysql&gt;set password for root@localhost=password('root');</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">删除匿名帐号：&nbsp;</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">mysql&gt;delete from user where user='';</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">删除密码为空的帐号：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">mysql&gt;delete from user where password='';</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">删除允许非localhost主机登录的帐号：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">mysql&gt;delete from user where host&lt;&gt;'localhost';</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">执行下面的命令使更改生效：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">mysql&gt;flush privileges;&nbsp;</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; line-height: 19px; white-space: normal; background-color: #28557e;">mysql&gt;update user set host = '%' where user = 'root';</div></code></strong></pre></div><img src ="http://www.blogjava.net/himalayas/aggbug/367700.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/himalayas/" target="_blank">himalayas</a> 2012-01-01 16:02 <a href="http://www.blogjava.net/himalayas/archive/2012/01/01/367700.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MYSQL字段int/bigint类型查询返回的结果不同（bug）</title><link>http://www.blogjava.net/himalayas/archive/2011/11/30/365162.html</link><dc:creator>himalayas</dc:creator><author>himalayas</author><pubDate>Wed, 30 Nov 2011 01:49:00 GMT</pubDate><guid>http://www.blogjava.net/himalayas/archive/2011/11/30/365162.html</guid><wfw:comment>http://www.blogjava.net/himalayas/comments/365162.html</wfw:comment><comments>http://www.blogjava.net/himalayas/archive/2011/11/30/365162.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/himalayas/comments/commentRss/365162.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/himalayas/services/trackbacks/365162.html</trackback:ping><description><![CDATA[<div><div>项目组的同学进来在使用mysql的时候发现了一个问题，具体内容如下：<br />MYSQL 版本 ： Server version: 5.1.48-log Source distribution<br /><img src="http://www.blogjava.net/images/blogjava_net/himalayas/mysql_bug.jpg" width="387" height="599" alt="" /><br /><br /><div><p style="margin-left:15.75pt"><strong><span style="font-size:14.0pt; font-family:宋体">咨询了</span></strong><strong><span style="font-size:14.0pt">DBA</span></strong><strong><span style="font-size:14.0pt;font-family:宋体">，我们发现在</span></strong><strong><span style="font-size:14.0pt">mysql</span></strong><strong><span style="font-size:14.0pt; font-family:宋体">进行值比较的时候</span></strong></p>  <p style="margin-left:15.75pt"><strong><span style="font-size:14.0pt;color:red">int</span></strong><strong><span style="font-size: 14.0pt;font-family:宋体;color:red">：使用</span></strong><strong><span style="font-size:14.0pt;color:red">decimal</span></strong><strong><span style="font-size: 14.0pt;font-family:宋体;color:red">类型比较（支持浮点数的比较）</span></strong></p>  <table border="0" cellspacing="0" cellpadding="0" style="margin-left:15.75pt;border-collapse:collapse;">  <tbody><tr>   <td width="590" valign="top" style="width:442.8pt;border:solid black 1.0pt;   padding:0cm 5.4pt 0cm 5.4pt">   <p><strong>Arg_comparator::compare_decimal </strong></p>   <p><strong>Arg_comparator::compare_decimal   (this=0x121cc2b8) at item_cmpfunc.cc:1378</strong></p>   <p><strong>1378&nbsp;&nbsp;&nbsp; int   Arg_comparator::compare_decimal()</strong></p>   </td>  </tr> </tbody></table>  <p style="margin-left:15.75pt"><strong><span style="font-size:14.0pt">&nbsp;</span></strong></p>  <p style="margin-left:15.75pt"><strong><span style="font-size:14.0pt;color:red">bigint</span></strong><strong><span style="font-size: 14.0pt;font-family:宋体;color:red">：使用</span></strong><strong><span style="font-size:14.0pt;color:red">int</span></strong><strong><span style="font-size: 14.0pt;font-family:宋体;color:red">类型比较</span></strong></p>  <table border="0" cellspacing="0" cellpadding="0" style="margin-left:15.75pt;border-collapse:collapse;">  <tbody><tr>   <td width="590" valign="top" style="width:442.8pt;border:solid black 1.0pt;   padding:0cm 5.4pt 0cm 5.4pt">   <p><strong>Arg_comparator::compare_int_signed </strong></p>   <p><strong>Arg_comparator::compare_int_signed   (this=0x121cc2b8) at item_cmpfunc.cc:1457</strong></p>   <p><strong>1457&nbsp; int   Arg_comparator::compare_int_signed()</strong></p>   </td>  </tr> </tbody></table></div></div></div><img src ="http://www.blogjava.net/himalayas/aggbug/365162.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/himalayas/" target="_blank">himalayas</a> 2011-11-30 09:49 <a href="http://www.blogjava.net/himalayas/archive/2011/11/30/365162.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle分页 导致数据总条数不变  而 出现重复记录的问题的解决办法</title><link>http://www.blogjava.net/himalayas/archive/2011/01/18/343168.html</link><dc:creator>himalayas</dc:creator><author>himalayas</author><pubDate>Tue, 18 Jan 2011 11:04:00 GMT</pubDate><guid>http://www.blogjava.net/himalayas/archive/2011/01/18/343168.html</guid><wfw:comment>http://www.blogjava.net/himalayas/comments/343168.html</wfw:comment><comments>http://www.blogjava.net/himalayas/archive/2011/01/18/343168.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/himalayas/comments/commentRss/343168.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/himalayas/services/trackbacks/343168.html</trackback:ping><description><![CDATA[今天在开发的时候用了oracle的分页，语句如下（ibatis）
<div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;SELECT *</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FROM (SELECT t1.*,rownum as linenum</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FROM (SELECT</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;A.MEMBERID memberID,</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;A.LOGNAME logName,</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;A.STATUS status,</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;A.UPDATETIME updateTime,</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;A.OPERATORNAME operatorName</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FROM BD_BAOYANG_LIST A</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;WHERE</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;![CDATA[</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A.TYPE='BUY'</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;]]&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;dynamic&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;isEqual property="status" compareValue="1" prepend="and"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A.STATUS=1</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/isEqual&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;isEqual property="status" compareValue="-1" prepend="and"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;![CDATA[</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A.STATUS&lt;&gt;1</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;]]&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/isEqual&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;isNotEmpty property="memberID" prepend="and"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A.MEMBERID = #memberID#</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/isNotEmpty&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;isNotEmpty property="logName" prepend="and"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A.LOGNAME = #logName#</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/isNotEmpty&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;isNotEmpty property="startTime" prepend="and"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;![CDATA[</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A.UPDATETIME &gt;= cast(#startTime# as DATE)</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;]]&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/isNotEmpty&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;isNotEmpty property="endTime" prepend="and"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;![CDATA[</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A.UPDATETIME &lt; cast(#endTime# as DATE)+1</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;]]&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/isNotEmpty&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;/dynamic&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;![CDATA[</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ORDER BY A.UPDATETIME DESC) t1</div>
<div><span class="Apple-tab-span" style="white-space:pre">					</span>WHERE ROWNUM &lt;= #endRow#) t2</div>
<div><span class="Apple-tab-span" style="white-space:pre">			</span> &nbsp;WHERE linenum &gt;= #startRow#</div>
<div><span class="Apple-tab-span" style="white-space:pre">	</span>]]&gt;</div>
</div>
<div>在运行后发现查询出来的结果总条数和数据库里的记录数量是一致的，但是出现了数据重复现象，也就是说有些数据被重复的记录替换了。</div>
<div>一开始以为是Java程序逻辑问题，经过认真的排查，排除了程序的问题。</div>
<div>仔细看了一下数据库里的数据，发现UPDATETIME这一列的数据格式是yyyy-MM-dd没有小时-分-秒的。这样该列的数据就出现了重复现象，这时我产生了疑问：难道oracle在对数据进行排序的时候对重复的排序条件是不能保证顺序的不变性？</div>
<div>带着这个问题我查询了oarcle的相关资料。</div>
<div>经过查询资料发现，oracle在对小量数据查询的时候会将数据放到缓存内进行排序，当数据量达到一定程度时会将数据在磁盘排序，而磁盘排序时当遇到排序条件相同的情况下，会根据该条记录的更新时间进行排序（我想可能是ROWID<img border="0" align="absmiddle" src="/CuteSoft_Client/CuteEditor/images/emsmilep.gif" alt="" />），但是如果放到内存排序的话如果不指定排序条件就不会走更新时间，因此我在上面的程序ORDER BY A.UPDATETIME DESC 修改成ORDER BY A.UPDATETIME DESC，A.ROWID DESC这样就解决了问题，但是这样解决的方式十分的不优雅，第一：这样UPDATETIME上建立的索引就不再起作用，第二：当该表数据量很大的时候，就会导致查询非常耗时，但是业务要求又必须按照UPDATETIME来进行排序，因此建议如果表的数据量很大就应该将该时间字段 提供 小时/分钟/秒钟</div>
<div>OVER!!!!!!!!!!!!</div><img src ="http://www.blogjava.net/himalayas/aggbug/343168.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/himalayas/" target="_blank">himalayas</a> 2011-01-18 19:04 <a href="http://www.blogjava.net/himalayas/archive/2011/01/18/343168.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ORACLE 物理分页</title><link>http://www.blogjava.net/himalayas/archive/2011/01/11/342770.html</link><dc:creator>himalayas</dc:creator><author>himalayas</author><pubDate>Tue, 11 Jan 2011 06:54:00 GMT</pubDate><guid>http://www.blogjava.net/himalayas/archive/2011/01/11/342770.html</guid><wfw:comment>http://www.blogjava.net/himalayas/comments/342770.html</wfw:comment><comments>http://www.blogjava.net/himalayas/archive/2011/01/11/342770.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/himalayas/comments/commentRss/342770.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/himalayas/services/trackbacks/342770.html</trackback:ping><description><![CDATA[<div>&lt;select id="FREEZE-SELECT" parameterClass="TA-FreezeAccountDO" resultClass="TA-FreezeAccountDO"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;SELECT</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;A.MEMBERID memberID,</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;A.LOGNAME logName,</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;A.STATUS status,</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;A.UPDATETIME updateTime</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FROM (SELECT RID</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FROM (SELECT RID, ROWNUM AS RN</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FROM (SELECT</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;A.ROWID RID</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FROM BD_BAOYANG_LIST A</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;WHERE</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;![CDATA[</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A.STATUS=#status#</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;]]&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;dynamic&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;isNotEmpty property="memberID" prepend="and"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A.MEMBERID = #memberID#</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/isNotEmpty&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;isNotEmpty property="logName" prepend="and"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A.LOGNAME = #logName#</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/isNotEmpty&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;isNotEmpty property="startTime" prepend="and"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;![CDATA[</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A.UPDATETIME &gt;= cast(#startTime# as DATE)</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;]]&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/isNotEmpty&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;isNotEmpty property="endTime" prepend="and"&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;![CDATA[</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A.UPDATETIME &lt; cast(#endTime# as DATE)+1</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;]]&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/isNotEmpty&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;/dynamic&gt;</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;![CDATA[</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ORDER BY A.MEMBERID)</div>
<div><span class="Apple-tab-span" style="white-space:pre">					</span>WHERE ROWNUM &lt;= #endRow#)</div>
<div><span class="Apple-tab-span" style="white-space:pre">			</span> &nbsp;WHERE RN &gt;= #startRow#) T1,BD_BAOYANG_LIST A</div>
<div><span class="Apple-tab-span" style="white-space:pre">			</span> &nbsp;WHERE T1.RID = A.ROWID</div>
<div><span class="Apple-tab-span" style="white-space:pre">		</span>ORDER BY A.MEMBERID</div>
<div><span class="Apple-tab-span" style="white-space:pre">	</span>]]&gt;</div>
<div>&nbsp;&nbsp; &nbsp;&lt;/select&gt;</div><img src ="http://www.blogjava.net/himalayas/aggbug/342770.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/himalayas/" target="_blank">himalayas</a> 2011-01-11 14:54 <a href="http://www.blogjava.net/himalayas/archive/2011/01/11/342770.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ORACLE 分页过程</title><link>http://www.blogjava.net/himalayas/archive/2011/01/11/342769.html</link><dc:creator>himalayas</dc:creator><author>himalayas</author><pubDate>Tue, 11 Jan 2011 06:41:00 GMT</pubDate><guid>http://www.blogjava.net/himalayas/archive/2011/01/11/342769.html</guid><wfw:comment>http://www.blogjava.net/himalayas/comments/342769.html</wfw:comment><comments>http://www.blogjava.net/himalayas/archive/2011/01/11/342769.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/himalayas/comments/commentRss/342769.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/himalayas/services/trackbacks/342769.html</trackback:ping><description><![CDATA[<div>--创建保存查询结果集的 cursor</div>
<div>create or replace package pkg_query as type cur_query is ref cursor; end pkg_query;</div>
<div>--插件存储过程</div>
<div>create or replace procedure Pagers(</div>
<div>v_cur out pkg_query.cur_query,--查询结果</div>
<div>numCount out number,--总记录数</div>
<div>page in number,--数据页数，从1开始</div>
<div>pageSize in number,--每页大小</div>
<div>tableName varchar2,--表名</div>
<div>strWhere varchar2,--where条件</div>
<div>Orderby varchar2</div>
<div>) is</div>
<div><br />
</div>
<div>strSql varchar2(2000);--获取数据的sql语句</div>
<div>pageCount number;--该条件下记录页数</div>
<div>startIndex number;--开始记录</div>
<div>endIndex number;--结束记录</div>
<div><br />
</div>
<div>begin</div>
<div><br />
</div>
<div>&nbsp;&nbsp;strSql:='select count(*) from '||tableName;</div>
<div>&nbsp;&nbsp;if strWhere is not null or strWhere&lt;&gt;'' then&nbsp;</div>
<div>&nbsp;&nbsp; &nbsp; strSql:=strSql||' where '||strWhere;</div>
<div>&nbsp;&nbsp;end if;&nbsp;</div>
<div>&nbsp;&nbsp;</div>
<div>&nbsp;&nbsp;EXECUTE IMMEDIATE strSql INTO numCount;</div>
<div>&nbsp;&nbsp;--计算数据记录开始和结束</div>
<div>&nbsp;&nbsp;pageCount:=numCount/pageSize+1;</div>
<div>&nbsp;&nbsp;startIndex:=(page-1)*pageSize+1;</div>
<div>&nbsp;&nbsp;endIndex:=page*pageSize;</div>
<div>&nbsp;&nbsp;</div>
<div>&nbsp;&nbsp;strSql:='select rownum ro, t.* from '||tableName||' t'; &nbsp;</div>
<div>&nbsp;&nbsp;strSql:=strSql||' where rownum&lt;='||endIndex;</div>
<div>&nbsp;&nbsp;</div>
<div>&nbsp;&nbsp;if strWhere is not null or strWhere&lt;&gt;'' then&nbsp;</div>
<div>&nbsp;&nbsp; &nbsp; strSql:=strSql||' and '||strWhere;</div>
<div>&nbsp;&nbsp;end if;</div>
<div>&nbsp;&nbsp;</div>
<div>&nbsp;&nbsp;if &nbsp;Orderby is not null or Orderby&lt;&gt;'' &nbsp;then&nbsp;</div>
<div>&nbsp;&nbsp; &nbsp; strSql:=strSql||' order by '||Orderby;</div>
<div>&nbsp;&nbsp;end if;</div>
<div>&nbsp;&nbsp;</div>
<div>&nbsp;&nbsp;strSql:='select * from ('||strSql||') where ro &gt;='||startIndex; &nbsp;</div>
<div>&nbsp;&nbsp;DBMS_OUTPUT.put_line(strSql);</div>
<div><br />
</div>
<div>&nbsp;&nbsp;OPEN v_cur FOR strSql;&nbsp;</div>
<div>end Pagers;</div>
<div><br />
</div><img src ="http://www.blogjava.net/himalayas/aggbug/342769.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/himalayas/" target="_blank">himalayas</a> 2011-01-11 14:41 <a href="http://www.blogjava.net/himalayas/archive/2011/01/11/342769.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>