<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>枫子博客SQL数据库</title>
	<atom:link href="http://www.imfeng.com/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.imfeng.com</link>
	<description>很枫的那种 闲人请勿靠近</description>
	<lastBuildDate>Sun, 05 Feb 2012 11:12:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL的复制原理及配置</title>
		<link>http://www.imfeng.com/mysql%e7%9a%84%e5%a4%8d%e5%88%b6%e5%8e%9f%e7%90%86%e5%8f%8a%e9%85%8d%e7%bd%ae/</link>
		<comments>http://www.imfeng.com/mysql%e7%9a%84%e5%a4%8d%e5%88%b6%e5%8e%9f%e7%90%86%e5%8f%8a%e9%85%8d%e7%bd%ae/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 16:33:06 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[主从]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=946</guid>
		<description><![CDATA[mysql的数据库的高可用性的架构大概有以下几种：集群，读写分离，主备。而后面两种都是通过复制来实现的。下面将简单介绍复制的原理及配置，以及一些常见的问题。mysql主从同步，请参考http://www.imfeng.com/linux-deploy-mysql-master-and-slave/
 
 
一。复制的原理
MySQL复制基于主服务器在二进制日志中跟踪所有对数据库的更改(更新、删除等等)。每个从服务器从主服务器接收主服务器已经记录到其二进制日志的保存的更新，以便从服务器可以对其数据拷贝执行相同的更新。
将主服务器的数据拷贝到从服务器的一个途径是使用LOAD DATA FROM MASTER语句。请注意LOAD DATA FROM MASTER目前只在所有表使用MyISAM存储引擎的主服务器上工作。并且，该语句将获得全局读锁定。
MySQL使用3个线程来执行复制功能,其中1个在主服务器上，另两个在从服务器上。当发出START SLAVE时，从服务器创建一个I/O线程，以连接主服务器并让它发送记录在其二进制日志中的语句。
主服务器创建一个线程将二进制日志中的内容发送到从服务器。该线程可以识别为主服务器上SHOW PROCESSLIST的输出中的Binlog Dump线程。
从服务器I/O线程读取主服务器Binlog Dump线程发送的内容并将该数据拷贝到从服务器数据目录中的本地文件中，即中继日志。
第3个线程是SQL线程，是从服务器创建用于读取中继日志并执行日志中包含的更新。
有多个从服务器的主服务器创建为每个当前连接的从服务器创建一个线程；每个从服务器有自己的I/O和SQL线程。
二。复制线程的状态
1.复制主线程的状态
Sending binlog event to slave
二进制日志由各种事件组成，一个事件通常为一个更新加一些其它信息。线程已经从二进制日志读取了一个事件并且正将它发送到从服务器。
Finished reading one binlog; switching to next binlog
线程已经读完二进制日志文件并且正打开下一个要发送到从服务器的日志文件。
Has sent all binlog to slave; waiting for binlog to be updated
线程已经从二进制日志读取所有主要的更新并已经发送到了从服务器。线程现在正空闲，等待由主服务器上新的更新导致的出现在二进制日志中的新事件。
Waiting to finalize termination
线程停止时发生的一个很简单的状态。
2.复制从I/O线程状态
Connecting to master
线程正试图连接主服务器。
Checking master version
建立同主服务器之间的连接后立即临时出现的状态。
Registering slave on master
建立同主服务器之间的连接后立即临时出现的状态。
Requesting binlog dump
建立同主服务器之间的连接后立即临时出现的状态。线程向主服务器发送一条请求，索取从请求的二进制日志文件名和位置开始的二进制日志的内容。
Waiting to reconnect after a failed binlog dump request
如果二进制日志转储请求失败(由于没有连接)，线程进入睡眠状态，然后定期尝试重新连接。可以使用&#8211;master-connect-retry选项指定重试之间的间隔。
Reconnecting after a [...]]]></description>
			<content:encoded><![CDATA[<p>mysql的数据库的高可用性的架构大概有以下几种：集群，读写分离，主备。而后面两种都是通过复制来实现的。下面将简单介绍复制的原理及配置，以及一些常见的问题。<a href="http://www.imfeng.com/linux-deploy-mysql-master-and-slave/">mysql主从同步</a>，请参考<a href="http://www.imfeng.com/linux-deploy-mysql-master-and-slave/">http://www.imfeng.com/linux-deploy-mysql-master-and-slave/</a><span id="more-946"></span></p>
<p> </p>
<p align="right"> </p>
<p>一。复制的原理<br />
MySQL复制基于主服务器在二进制日志中跟踪所有对数据库的更改(更新、删除等等)。每个从服务器从主服务器接收主服务器已经记录到其二进制日志的保存的更新，以便从服务器可以对其数据拷贝执行相同的更新。<br />
将主服务器的数据拷贝到从服务器的一个途径是使用LOAD DATA FROM MASTER语句。请注意LOAD DATA FROM MASTER目前只在所有表使用MyISAM存储引擎的主服务器上工作。并且，该语句将获得全局读锁定。</p>
<p>MySQL使用3个线程来执行复制功能,其中1个在主服务器上，另两个在从服务器上。当发出START SLAVE时，从服务器创建一个I/O线程，以连接主服务器并让它发送记录在其二进制日志中的语句。<br />
主服务器创建一个线程将二进制日志中的内容发送到从服务器。该线程可以识别为主服务器上SHOW PROCESSLIST的输出中的Binlog Dump线程。<br />
从服务器I/O线程读取主服务器Binlog Dump线程发送的内容并将该数据拷贝到从服务器数据目录中的本地文件中，即中继日志。<br />
第3个线程是SQL线程，是从服务器创建用于读取中继日志并执行日志中包含的更新。<br />
有多个从服务器的主服务器创建为每个当前连接的从服务器创建一个线程；每个从服务器有自己的I/O和SQL线程。<br />
二。复制线程的状态</p>
<p>1.复制主线程的状态<br />
Sending binlog event to slave<br />
二进制日志由各种事件组成，一个事件通常为一个更新加一些其它信息。线程已经从二进制日志读取了一个事件并且正将它发送到从服务器。</p>
<p>Finished reading one binlog; switching to next binlog<br />
线程已经读完二进制日志文件并且正打开下一个要发送到从服务器的日志文件。</p>
<p>Has sent all binlog to slave; waiting for binlog to be updated<br />
线程已经从二进制日志读取所有主要的更新并已经发送到了从服务器。线程现在正空闲，等待由主服务器上新的更新导致的出现在二进制日志中的新事件。</p>
<p>Waiting to finalize termination<br />
线程停止时发生的一个很简单的状态。</p>
<p>2.复制从I/O线程状态<br />
Connecting to master<br />
线程正试图连接主服务器。</p>
<p>Checking master version<br />
建立同主服务器之间的连接后立即临时出现的状态。</p>
<p>Registering slave on master<br />
建立同主服务器之间的连接后立即临时出现的状态。</p>
<p>Requesting binlog dump<br />
建立同主服务器之间的连接后立即临时出现的状态。线程向主服务器发送一条请求，索取从请求的二进制日志文件名和位置开始的二进制日志的内容。</p>
<p>Waiting to reconnect after a failed binlog dump request<br />
如果二进制日志转储请求失败(由于没有连接)，线程进入睡眠状态，然后定期尝试重新连接。可以使用&#8211;master-connect-retry选项指定重试之间的间隔。</p>
<p>Reconnecting after a failed binlog dump request<br />
线程正尝试重新连接主服务器。</p>
<p>Waiting for master to send event<br />
线程已经连接上主服务器，正等待二进制日志事件到达。如果主服务器正空闲，会持续较长的时间。如果等待持续slave_read_timeout秒，则发生超时。此时，线程认为连接被中断并企图重新连接。</p>
<p>Queueing master event to the relay log<br />
线程已经读取一个事件，正将它复制到中继日志供SQL线程来处理。</p>
<p>Waiting to reconnect after a failed master event read<br />
读取时(由于没有连接)出现错误。线程企图重新连接前将睡眠master-connect-retry秒。</p>
<p>Reconnecting after a failed master event read<br />
线程正尝试重新连接主服务器。当连接重新建立后，状态变为Waiting for master to send event。</p>
<p>Waiting for the slave SQL thread to free enough relay log space<br />
正使用一个非零relay_log_space_limit值，中继日志已经增长到其组合大小超过该值。I/O线程正等待直到SQL线程处理中继日志内容并删除部分中继日志文件来释放足够的空间。</p>
<p>Waiting for slave mutex on exit<br />
线程停止时发生的一个很简单的状态。</p>
<p>3.复制从SQL线程状态<br />
Reading event from the relay log<br />
线程已经从中继日志读取一个事件，可以对事件进行处理了。</p>
<p>Has read all relay log; waiting for the slave I/O thread to update it<br />
线程已经处理了中继日志文件中的所有事件，现在正等待I/O线程将新事件写入中继日志。</p>
<p>Waiting for slave mutex on exit<br />
线程停止时发生的一个很简单的状态。<br />
三。复制传递和状态文件<br />
从服务器靠中继日志来接收从主服务器上传回来的日志。并依靠状态文件来记录已经从主服务器接收了哪些日志，已经恢复了哪些日志。</p>
<p>中继日志与二进制日志的格式相同，并且可以用mysqlbinlog读取。SQL线程执行完中继日志中的所有事件并且不再需要之后，立即自动删除它。可以采用&#8211;relay-log和&#8211;relay-log-index服务器选项覆盖默认中继日志和索引文件名。其中索引文件名的作用是记录目前正在使用中继日志。</p>
<p>在下面的条件下将创建新的中继日志：<br />
1.每次I/O线程启动时创建一个新的中继日志。<br />
2.当日志被刷新时；例如，用FLUSH LOGS或mysqladmin flush-logs。<br />
3.当当前的中继日志文件变得太大时。“太大”含义的确定方法：<br />
max_relay_log_size，如果max_relay_log_size &gt; 0<br />
max_binlog_size，如果max_relay_log_size = 0<br />
状态文件名默认为master.info和relay-log.info。其中IO线程更新master.info文件，SQL线程更新relay-log.info文件。<br />
文件中的行和SHOW SLAVE STATUS显示的列的对应关系为：<br />
master.info文件：<br />
行 描述<br />
1 文件中的行号<br />
2 Master_Log_File<br />
3 Read_Master_Log_Pos<br />
4 Master_Host<br />
5 Master_User<br />
6 密码(不由SHOW SLAVE STATUS显示)<br />
7 Master_Port<br />
8 Connect_Retry<br />
9 Master_SSL_Allowed<br />
10 Master_SSL_CA_File<br />
11 Master_SSL_CA_Path<br />
12 Master_SSL_Cert<br />
13 Master_SSL_Cipher<br />
14 Master_SSL_Key</p>
<p>relay-log.info文件：<br />
行 描述<br />
1 Relay_Log_File<br />
2 Relay_Log_Pos<br />
3 Relay_Master_Log_File<br />
4 Exec_Master_Log_Pos</p>
<p>当备份从服务器的数据时，你还应备份这两个小文件以及中继日志文件。它们用来在恢复从服务器的数据后继续进行复制。如果丢失了中继日志但仍然有relay-log.info文件，你可以通过检查该文件来确定SQL线程已经执行的主服务器中二进制日志的程度。然后可以用Master_Log_File和Master_LOG_POS选项执行CHANGE MASTER TO来告诉从服务器重新从该点读取二进制日志。当然，要求二进制日志仍然在主服务器上。所以最好建议将自动删除中继日志的特性关闭，手工写shell角本来防止空间满的问题。<br />
四。复制的配置步骤</p>
<p>1.创建专门用于复制的用户(建议这样做)，从服务器采用该帐户登陆主服务器：<br />
GRANT REPLICATION SLAVE ON *.* TO <a href="mailto:'rep'@'%'">&#8216;rep&#8217;@'%&#8217;</a> IDENTIFIED BY &#8216;logzgh&#8217;;</p>
<p>如果你计划从从属服务器主机使用LOAD TABLE FROM MASTER或LOAD DATA FROM MASTER语句，你需要授予该账户其它权限：<br />
授予账户SUPER和RELOAD全局权限。<br />
为所有想要装载的表授予SELECT权限。任何该 账户不能SELECT的主服务器上的表被LOAD DATA FROM MASTER忽略掉。</p>
<p>2.将数据库文件移到从服务器上<br />
情况一：若只用到MyISAM表<br />
mysql&gt; FLUSH TABLES WITH READ LOCK;<br />
(刷新所有表并且阻止其它写入，不要退出该客户端，以保持读锁有效。若退出，读锁就会释放。)<br />
比较简单的办法就是把数据目录打包压缩。<br />
$ tar -cvf /home/mysql/snapshot.tar ./data (在master上)<br />
$ tar -xvf /home/mysql/snapshot.tar (在slave上)<br />
可能不需要同步 mysql 数据库，因为在slave上的权限表和master不一样。这时，解开压缩包的时候要排除它。<br />
同时在压缩包中也不要包含任何日志文件，和状态文件master.info、relay-log.info。<br />
mysql&gt; SHOW MASTER STATUS;<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| mysql-bin.000058 | 45036137 | | |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</p>
<p>mysql&gt; UNLOCK TABLES;<br />
情况二：若用到InnoDB表<br />
方法一：使用InnoDB Hot Backup工具。它无需在master上请求任何锁就能做到快照的一致性，并且在后面中在slave上要用到的快照中已经记录了日志文件名以及偏移位置。 (<a href="http://www.innodb.com/manual.php">http://www.innodb.com/manual.php</a>)<br />
方法二：记录当前日志文件及偏移位置，在master关闭前执行：<br />
mysql&gt; FLUSH TABLES WITH READ LOCK;<br />
mysql&gt; SHOW MASTER STATUS;<br />
尽快记下显示结果中的日志文件及偏移位置。然后，在不解锁的情况下关闭master，确保master上的快照和记录的结果一致。<br />
关闭master服务器，$ mysqladmin -u root shutdown<br />
拷贝 InnoDB 数据文件，日志文件，以及表结构定义文件(.frm文件)。<br />
情况三：可以同时用于MyISAM和InnoDB表<br />
在master上做SQL转储而无需如上所述备份二进制日志。运行mysqldump &#8211;master-data命令，然后把结果文件转储到slave上。<br />
不过，这比拷贝二进制日志慢点。</p>
<p>3.修改my.cnf文件<br />
在master上my.cnf文件：(重启生效)<br />
[mysqld]<br />
log_bin<br />
server_id=1 (值是 1 到 2^32-1 之间的正整数)<br />
在slave上my.cnf文件：<br />
[mysqld]<br />
server_id=2 (ID必须和master的ID不同。若有多个slave，则每个slave都必须有唯一的id。)</p>
<p>配置slave的扩展选项<br />
master_host=db-master.mycompany.com<br />
master_port=3306<br />
master_user=rep<br />
master_password=freitag<br />
master_connect_retry=60 (若master宕机或者slave连接断开，slave会定期尝试连接到master上，重试的间隔由该选项来控制，默认值是60秒。)<br />
report_host=db-slave.mycompany.com<br />
slave_net_timeout=3600 (slave默认会在3600秒后，若还没收到来自master的数据，则会当作网络断开的情况来处理。)</p>
<p>服务器认为master.info的优先级比配置文件my.cnf高，<br />
第一次启动slave时，master.info不存在，它从my.cnf中读取选项值，然后把它们保存在master.info中。<br />
下次重启slave时，它只读取master.info的内容，而不会读取my.cnf中的选项值。<br />
想要使用不同的选项值，可以删除master.info后重启slave，或者使用CHANGE MASTER TO语句(推荐)重置选项值。<br />
4.启动从服务器线程<br />
mysqld_safe &#8211;user=mysql &#8211;skip-slave-start &amp; (启动MySQL服务器，但不启动slave)<br />
设置master_log_file等参数<br />
mysql&gt; CHANGE MASTER TO MASTER_HOST=&#8217;qa-sandbox-1&#8242;,<br />
MASTER_USER=&#8217;rep&#8217;,<br />
MASTER_PASSWORD=&#8217;logzgh&#8217;,<br />
MASTER_LOG_FILE=&#8217;mysql-bin.000007&#8242;,<br />
MASTER_LOG_POS=471632;</p>
<p>mysql&gt; START SLAVE；<br />
执行这些程序后，从服务器应连接主服务器，并补充自从快照以来发生的任何更新。<br />
如果你忘记设置主服务器的server-id值，从服务器不能连接主服务器。</p>
<p>注释：为了保证事务InnoDB复制设置的最大可能的耐受性和一致性，<br />
应在主服务器的my.cnf文件中使用innodb_flush_log_at_trx_commit=1和sync-binlog=1。</p>
<p>mysql&gt; show variables; (检查是否read-only，该选项令slave除了slave线程或者拥有SUPER权限用户之外的都不能更新数据，确保slave不会接受来自其他客户端的更新。)<br />
mysql&gt; show processlist; (检查是否slave-start)</p>
<p>在启动mysql的同时启动slave：<br />
mysqld_safe &#8211;user=mysql &#8211;read-only &amp; (启动MySQL服务器，同时启动slave的I/O线程)</p>
<p>mysql&gt; SHOW SLAVE STATUSG;</p>
<p>5.切换slave为master，在slave上：<br />
mysql&gt; STOP SLAVE;<br />
mysql&gt; RESET MASTER;<br />
五.复制启动选项</p>
<p>&#8211;read_only<br />
该选项让从服务器只允许来自从服务器线程或具有SUPER权限的用户的更新。可以确保从服务器不接受来自客户的更新。</p>
<p>&#8211;replicate_do_db=db_name<br />
告诉从服务器只做默认数据库(由USE所选择)为db_name的语句的复制。要指定多个数据库，应多次使用该选项，每个数据库使用一次。请注意不复制跨数据库的语句</p>
<p>&#8211;replicate_do_table=db_name.tbl_name<br />
告诉从服务器线程只做对指定表的复制。要指定多个表，应多次使用该选项，每个表使用一次。同&#8211;replicate-do-db对比，允许跨数据库更新。</p>
<p>&#8211;replicate_ignore_db=db_name<br />
告诉从服务器不要复制默认数据库(由USE所选择)为db_name的语句。要想忽略多个数据库，应多次使用该选项，每个数据库使用一次。</p>
<p>&#8211;replicate-ignore-table=db_name.tbl_name<br />
告诉从服务器线程不要复制更新指定表的任何语句(即使该语句可能更新其它的表)。要想忽略多个表，应多次使用该选项，每个表使用一次。</p>
<p>&#8211;replicate_wild_do_table=db_name.tbl_name<br />
告诉从服务器线程限制复制更新的表匹配指定的数据库和表名模式的语句。模式可以包含‘%’和‘_’通配符，与LIKE模式匹配操作符具有相同的含义。要指定多个表，应多次使用该选项，每个表使用一次。该选项可以跨数据库进行更新。</p>
<p>&#8211;replicate_wild_ignore_table=db_name.tbl_name<br />
告诉从服务器线程不要复制表匹配给出的通配符模式的语句。要想忽略多个表，应多次使用该选项，每个表使用一次。该选项可以跨数据库进行更新。</p>
<p>&#8211;replicate_rewrite_db=from_name-&gt;to_name<br />
告诉从服务器如果默认数据库(由USE所选择)为主服务器上的from_name，则翻译为to_name。只影响含有表的语句</p>
<p>&#8211;report_host=slave_name<br />
从服务器注册过程中报告给主服务器的主机名或IP地址。该值出现在主服务器上SHOW SLAVE HOSTS的输出中。如果不想让从服务器自己在主服务器上注册，则不设置该值。</p>
<p>&#8211;report_port=slave_port<br />
连接从服务器的TCP/IP端口号，从服务器注册过程中报告给主服务器。</p>
<p>&#8211;skip_slave_start<br />
告诉从服务器当服务器启动时不启动从服务器线程。使用START SLAVE语句在以后启动线程。</p>
<p>&#8211;slave_skip_errors=[err_code1,err_code2,... | all]<br />
通常情况，当出现错误时复制停止，这样给你一个机会手动解决数据中的不一致性问题。该选项告诉从服务器SQL线程当语句返回任何选项值中所列的错误时继续复制。<br />
例如：<br />
&#8211;slave-skip-errors=1062,1053<br />
&#8211;slave-skip-errors=all</p>
<p>六.不停机配置复制的方法</p>
<p>方法一：<br />
如果你在某时间点做过主服务器备份并且记录了相应快照的二进制日志名和偏移量(通过SHOW MASTER STATUS命令的输出)，采用下面的步骤：</p>
<p>1. 确保从服务器分配了一个唯一的服务器ID号。<br />
2. 将备份文件拷到从服务器上。<br />
3. 在从服务器上执行下面的语句，为每个选项填入适当的值：<br />
mysql&gt; CHANGE MASTER TO<br />
-&gt; MASTER_HOST=&#8217;master_host_name&#8217;,<br />
-&gt; MASTER_USER=&#8217;master_user_name&#8217;,<br />
-&gt; MASTER_PASSWORD=&#8217;master_pass&#8217;,<br />
-&gt; MASTER_LOG_FILE=&#8217;recorded_log_file_name&#8217;,<br />
-&gt; MASTER_LOG_POS=recorded_log_position;</p>
<p>4.在从服务器上执行START SLAVE语句。</p>
<p>如果你没有备份主服务器，这里是一个创建备份的快速程序。所有步骤都应该在主服务器主机上执行。</p>
<p>1. 发出该语句：<br />
mysql&gt; FLUSH TABLES WITH READ LOCK；<br />
2. 仍然加锁时，执行该命令（或它的变体）：<br />
shell&gt; tar zcf /tmp/backup.tar.gz /var/lib/mysql<br />
并拷到从服务器上。<br />
3. 发出该语句并且确保记录了以后用到的输出：<br />
mysql&gt;SHOW MASTER STATUS；<br />
4. 释放锁：<br />
mysql&gt; UNLOCK TABLES；</p>
<p>方法二：<br />
一个可选择的方法是，转储主服务器的SQL来代替前面步骤中的二进制复制。要这样做，你可以在主服务器上使用mysqldump &#8211;master-data，以后装载SQL转储到到你的从服务器。然而，这比进行二进制复制速度慢。</p>
<p> </p>
<p>七.其他</p>
<p>1.不能从使用新二进制日志格式的主服务器向使用旧二进制日志格式的从服务器复制。<br />
2.升级从服务器时，应先关闭从服务器，升级到相应5.1.x版本，然后重启从服务器并重新开始复制。5.1版本的从服务器能够读取升级前写入的旧的中继日志并执行日志中包含的语句。升级后从服务器创建的中继日志为5.1格式。</p>
<p>3.必须在主服务器和从服务器上总是使用相同的全局字符集和校对规则(&#8211;default-character-set、&#8211;default-collation)。否则，会在从服务器上遇到复制键值错误，因为在主服务器的字符集中被认为是唯一的键值在从服务器的字符集中可能不是唯一的。<br />
4.Q：从服务器需要始终连接到主服务器吗？<br />
A：不，不需要。从服务器可以宕机或断开连接几个小时甚至几天，重新连接后获得更新信息。</p>
<p>5.Q：我怎样知道从服务器与主服务器的最新比较? 换句话说，我怎样知道从服务器复制的最后一个查询的日期？<br />
A：你可以查看SHOW SLAVE STATUS语句的Seconds_Behind_Master列的结果。</p>
<p>6. Q：我怎样强制主服务器阻塞更新直到从服务器同步？<br />
A：使用下面的步骤：<br />
1. 在主服务器上，执行这些语句：<br />
mysql&gt; FLUSH TABLES WITH READ LOCK;<br />
mysql&gt; SHOW MASTER STATUS;<br />
记录SHOW语句的输出的日志名和偏移量。这些是复制坐标。</p>
<p>2.在从服务器上，发出下面的语句，其中Master_POS_WAIT()函数的参量是前面步骤中的得到的复制坐标值：<br />
mysql&gt; SELECT MASTER_POS_WAIT(&#8217;log_name&#8217;, log_offset);<br />
SELECT语句阻塞直到从服务器达到指定的日志文件和偏移量。此时，从服务器与主服务器同步，语句返回。</p>
<p>3.在主服务器上，发出下面的语句允许主服务器重新开始处理更新：<br />
mysql&gt; UNLOCK TABLES；</p>
<p>7.Q：怎样通过复制来提高系统的性能？<br />
A：你应将一个服务器设置为主服务器并且将所有写指向该服务器。然后根据预算配置尽可能多的从服务器以及栈空间，并且在主服务器和从服务器之间分发读取操作。你也可以用&#8211;skip-innodb、&#8211;skip-bdb、&#8211;low-priority-updates以及&#8211;delay-key-write=ALL选项启动从服务器，以便在从服务器端提高速度。在这种情况下，为了提高速度，从服务器使用非事务MyISAM表来代替InnoDB和BDB表。</p>
<p>转载:<a href="http://logzgh.itpub.net/post/3185/453268">http://logzgh.itpub.net/post/3185/453268</a></p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/mysql%e7%9a%84%e5%a4%8d%e5%88%b6%e5%8e%9f%e7%90%86%e5%8f%8a%e9%85%8d%e7%bd%ae/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux部署Mysql数据库主从同步</title>
		<link>http://www.imfeng.com/linux-deploy-mysql-master-and-slave/</link>
		<comments>http://www.imfeng.com/linux-deploy-mysql-master-and-slave/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 16:59:52 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[同步]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=918</guid>
		<description><![CDATA[搞了一天，最后没办法，在hostloc和im286还有微博里面求救，有一个hostloc的朋友(醒醒)加我QQ，帮了挺多的，再次感谢。
最后，我们实在找不到问题的所在，我还原了主服务器和从服务器的my.cnf，一步一步来。
主服务器IP: 250.110.120.119
从服务器IP: 110.120.119.250
1.在主服务器新建一个用户，给从服务器同步使用。


GRANT ALL PRIVILEGES ON *.* TO 'tongbu'@'110.120.119.250.' IDENTIFIED BY 'tongbu';

意思是新建一个用户名为tongbu 密码为tongbu 具有所有操作权限的帐号。
2.修改主服务器my.cnf文件
其实这一步可以省略，因为保持默认的配置文件就可以了。
/*
添加
server-id=1
并开启log-bin二进制日志文件
log-bin=mysql-bin
注:需要把默认的server-id=1去掉
*/
3.重启主服务器mysql数据库
4.进入mysql界面执行下面命令 获取日志文件名和偏移量

show master status;

显示如:
mysql&#62; show master status;
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+
&#124; File &#124; Position &#124; Binlog_Do_DB &#124; Binlog_Ignore_DB &#124;
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+
&#124; mysql-bin.000010 &#124; 106 &#124; &#124; &#124;
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+
1 row in set (0.00 sec)
得到的日志文件名为 mysql-bin.000010 偏移量为106
5.修改从服务器的my.cnf
添加一个
server-id=2
注:需要把默认的server-id=1去掉
6.重启从服务器mysql数据库
7.对从数据库进行设置，@@@这是最最重要的地方。


change master to master_host='250.110.120.119', master_user='tongbu', master_password='tongbu', master_log_file='mysql-bin.000010', master_log_pos=106;

8.启动从服务器

start slave;

9.执行下面命令 查看进程

show processlist\G

显示如下
mysql&#62; show processlist\G
*************************** 1. row [...]]]></description>
			<content:encoded><![CDATA[<p>搞了一天，最后没办法，在hostloc和im286还有微博里面求救，有一个<a href="http://www.hostloc.com/thread-98183-1-2.html">hostloc</a>的朋友(醒醒)加我QQ，帮了挺多的，再次感谢。<span id="more-918"></span></p>
<p>最后，我们实在找不到问题的所在，我还原了主服务器和从服务器的my.cnf，一步一步来。</p>
<p>主服务器IP: 250.110.120.119<br />
从服务器IP: 110.120.119.250</p>
<p>1.在主服务器新建一个用户，给从服务器同步使用。</p>
<pre class="brush: php; title: ;">

GRANT ALL PRIVILEGES ON *.* TO 'tongbu'@'110.120.119.250.' IDENTIFIED BY 'tongbu';
</pre>
<p>意思是新建一个用户名为tongbu 密码为tongbu 具有所有操作权限的帐号。</p>
<p>2.修改主服务器my.cnf文件<br />
其实这一步可以省略，因为保持默认的配置文件就可以了。<br />
/*<br />
添加<br />
server-id=1<br />
并开启log-bin二进制日志文件<br />
log-bin=mysql-bin<br />
注:需要把默认的server-id=1去掉<br />
*/</p>
<p>3.重启主服务器mysql数据库</p>
<p>4.进入mysql界面执行下面命令 获取日志文件名和偏移量</p>
<pre class="brush: php; title: ;">
show master status;
</pre>
<p>显示如:<br />
mysql&gt; show master status;<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| <span style="color: #ff0000;">mysql-bin.000010 | 106</span> | | |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
1 row in set (0.00 sec)</p>
<p>得到的日志文件名为 mysql-bin.000010 偏移量为106</p>
<p>5.修改从服务器的my.cnf<br />
添加一个<br />
server-id=2<br />
注:需要把默认的server-id=1去掉</p>
<p>6.重启从服务器mysql数据库</p>
<p>7.对从数据库进行设置，@@@这是最最重要的地方。</p>
<pre class="brush: php; title: ;">

change master to master_host='250.110.120.119', master_user='tongbu', master_password='tongbu', master_log_file='mysql-bin.000010', master_log_pos=106;
</pre>
<p>8.启动从服务器</p>
<pre class="brush: php; title: ;">
start slave;
</pre>
<p>9.执行下面命令 查看进程</p>
<pre class="brush: php; title: ;">
show processlist\G
</pre>
<p>显示如下<br />
mysql&gt; <span style="color: #ff0000;">show processlist\G<br />
</span>*************************** 1. row ***************************<br />
Id: 4<br />
User: root<br />
Host: localhost<br />
db: test<br />
Command: Query<br />
Time: 0<br />
State: NULL<br />
Info: show processlist<br />
*************************** 2. row ***************************<br />
Id: 5<br />
User: system user<br />
Host:<br />
db: NULL<br />
Command: Connect<br />
Time: 1773<br />
State: Waiting for master to send event<br />
Info: NULL<br />
*************************** 3. row ***************************<br />
Id: 6<br />
User: system user<br />
Host:<br />
db: NULL<br />
Command: Connect<br />
Time: 1630<br />
State: <span style="color: #ff0000;">Has read all relay log; waiting for the slave I/O thread to update it<br />
</span>Info: NULL<br />
3 rows in set (0.00 sec)</p>
<p>10.查看从服务器状态</p>
<pre class="brush: php; title: ;">
show slave status\G
</pre>
<p>显示如下<br />
mysql&gt; show slave status\G<br />
*************************** 1. row ***************************<br />
<span style="color: #ff0000;">Slave_IO_State: Waiting for master to send event<br />
</span>Master_Host: 250.110.120.119<br />
Master_User: tongbu<br />
Master_Port: 3306<br />
Connect_Retry: 60<br />
Master_Log_File: mysql-bin.000010<br />
Read_Master_Log_Pos: 281<br />
Relay_Log_File: up2-relay-bin.000002<br />
Relay_Log_Pos: 426<br />
Relay_Master_Log_File: mysql-bin.000010<br />
<span style="color: #ff0000;">Slave_IO_Running: Yes<br />
Slave_SQL_Running: Yes<br />
</span>Replicate_Do_DB:<br />
Replicate_Ignore_DB:<br />
Replicate_Do_Table:<br />
Replicate_Ignore_Table:<br />
Replicate_Wild_Do_Table:<br />
Replicate_Wild_Ignore_Table:<br />
Last_Errno: 0<br />
Last_Error:<br />
Skip_Counter: 0<br />
Exec_Master_Log_Pos: 281<br />
Relay_Log_Space: 579<br />
Until_Condition: None<br />
Until_Log_File:<br />
Until_Log_Pos: 0<br />
Master_SSL_Allowed: No<br />
Master_SSL_CA_File:<br />
Master_SSL_CA_Path:<br />
Master_SSL_Cert:<br />
Master_SSL_Cipher:<br />
Master_SSL_Key:<br />
Seconds_Behind_Master: 0<br />
Master_SSL_Verify_Server_Cert: No<br />
Last_IO_Errno: 0<br />
Last_IO_Error:<br />
Last_SQL_Errno: 0<br />
Last_SQL_Error:<br />
1 row in set (0.00 sec)</p>
<p>测试:<br />
1、在主服务器test数据库中创建user表<br />
mysql&gt;use test;<br />
mysql&gt;create table user(id int);<br />
2、在从服务器中查看user表<br />
mysql&gt;use test;<br />
mysql&gt; show tables like ‘user’;<br />
+———————-+<br />
| Tables_in_test(user) |<br />
+———————-+<br />
| user |<br />
+———————-+<br />
1 row in set (0.00 sec)<br />
说明主从数据同步成功。</p>
<p>部分参考:<a href="http://database.51cto.com/art/201009/223213.htm">http://database.51cto.com/art/201009/223213.htm</a></p>
<p>附录:</p>
<pre class="brush: php; title: ;">

cp /usr/local/mysql/share/mysql/my-medium.cnf  /etc/my.cnf

/usr/local/mysql/bin/mysql -u root -p

show master status;

show variables like 'server_id';

set global server_id=2;

slave start;

slave stop;

show slave status\G

show processlist\G

flush privileges;

/usr/local/mysql/bin/mysql -h110.120.119.250 -uroot -proot123
</pre>
<p>############################################################</p>
<p>如果您看完文章，自己测试还是不成功，可以购买枫子的收费服务。</p>
<p><img src="http://www.imfeng.com/upload/beian7.jpg" alt="批量查询域名备案" width="396" height="153" /></p>
<p>请注明 mysql同步 50元部署主从实时同步。</p>
By the time  your rss reader get this post here is <strong> 3 </strong>comments ,Welcome you come to leave your opinion !]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-deploy-mysql-master-and-slave/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ERROR! Manager of pid-file quit without updating file 解决办法</title>
		<link>http://www.imfeng.com/error-manager-of-pid-file-quit-without-updating-file-%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/</link>
		<comments>http://www.imfeng.com/error-manager-of-pid-file-quit-without-updating-file-%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 07:16:02 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[ERROR]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[解决方法]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=914</guid>
		<description><![CDATA[很久以前就知道出现&#8221;ERROR! Manager of pid-file quit without updating file&#8221;是权限的问题，今天又遇到了，烦躁。
最后发现没有给var文件夹写的权限，因为它要写错误信息到xxx.err。


chmod -R 777 var

Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>很久以前就知道出现&#8221;ERROR! Manager of pid-file quit without updating file&#8221;是权限的问题，今天又遇到了，烦躁。</p>
<p>最后发现没有给var文件夹写的权限，因为它要写错误信息到xxx.err。</p>
<pre class="brush: php; title: ;">

chmod -R 777 var
</pre>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/error-manager-of-pid-file-quit-without-updating-file-%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql 出现Table &#8216;xxx&#8217; is read only 解决办法</title>
		<link>http://www.imfeng.com/mysql-got-table-xxx-is-read-only/</link>
		<comments>http://www.imfeng.com/mysql-got-table-xxx-is-read-only/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 14:17:48 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[解决]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=900</guid>
		<description><![CDATA[在Linux下面执行下面命令就可以了，当然你要找到你的mysql目录
/usr/local/mysql/bin/mysqladmin -u root -p flush-tables
如果你是Windows的话，登录mysql 然后执行 flush-tables 即可。
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>在Linux下面执行下面命令就可以了，当然你要找到你的mysql目录</p>
<pre class="brush: php; title: ;">/usr/local/mysql/bin/mysqladmin -u root -p flush-tables</pre>
<p>如果你是Windows的话，登录mysql 然后执行 flush-tables 即可。</p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/mysql-got-table-xxx-is-read-only/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql获取随机数rand()函数优化</title>
		<link>http://www.imfeng.com/mysql-get-rand/</link>
		<comments>http://www.imfeng.com/mysql-get-rand/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 11:14:44 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rand]]></category>
		<category><![CDATA[优化]]></category>
		<category><![CDATA[函数]]></category>
		<category><![CDATA[随机数]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=757</guid>
		<description><![CDATA[从数据表随机获取N条数据记录的方法有很多，其中最简单的莫过于SELECT * FROM `table` WHERE 1 ORDER BY rand() LIMIT N 这个语句得好处在于简单，但前提条件是查询的结果集必须小于5W记录集的情况下方可使用，若数据结果集超过了5W，其查询出来的速度将非常的耗资源。
下面语句枫子是在数据库记录数16,246,264(1600W)条下进行测试的。


SELECT * FROM `baidu` AS k1 JOIN (
    SELECT ROUND( RAND( ) * (
        (SELECT MAX( id ) FROM `baidu` ) - (SELECT MIN( id ) FROM `baidu` ) ) +
            (SELECT MIN( id ) FROM `baidu` )) AS id
         ) AS k2
    WHERE [...]]]></description>
			<content:encoded><![CDATA[<p>从数据表随机获取N条数据记录的方法有很多，其中最简单的莫过于SELECT * FROM `table` WHERE 1 ORDER BY rand() LIMIT N 这个语句得好处在于简单，但前提条件是查询的结果集必须小于5W记录集的情况下方可使用，若数据结果集超过了5W，其查询出来的速度将非常的耗资源。</p>
<p>下面语句<a href="http://www.imfeng.com/">枫子</a>是在数据库记录数16,246,264(1600W)条下进行测试的。<span id="more-757"></span></p>
<pre class="brush: php; title: ;">

SELECT * FROM `baidu` AS k1 JOIN (
    SELECT ROUND( RAND( ) * (
        (SELECT MAX( id ) FROM `baidu` ) - (SELECT MIN( id ) FROM `baidu` ) ) +
            (SELECT MIN( id ) FROM `baidu` )) AS id
         ) AS k2
    WHERE k1.id &gt;= k2.id LIMIT 10

0.0445秒 连续记录

 

SELECT * FROM `baidu`
WHERE id &gt;= (SELECT floor(RAND() * (SELECT MAX(id) FROM `baidu`)))
ORDER BY id LIMIT 10;

 0.0710 不连续

 

SELECT *
FROM `baidu` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `baidu`)-(SELECT MIN(id) FROM `baidu`))+(SELECT MIN(id) FROM `baidu`)) AS id) AS t2
WHERE t1.id &gt;= t2.id
ORDER BY t1.id LIMIT 10;
0.0203 连续的

SELECT * FROM `baidu`
WHERE id &gt;= (SELECT floor( RAND() * ((SELECT MAX(id) FROM `baidu`)-(SELECT MIN(id) FROM `baidu`)) + (SELECT MIN(id) FROM `baidu`)))
ORDER BY id LIMIT 10;
0.0668 不连续

 

 
</pre>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/mysql-get-rand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux开通mysql支持InnoDB</title>
		<link>http://www.imfeng.com/linux-let-mysql-support-innodb/</link>
		<comments>http://www.imfeng.com/linux-let-mysql-support-innodb/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 14:35:20 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[InnoDB]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=719</guid>
		<description><![CDATA[很多情况下，默认安装的mysql是不支持InnoDB这个存储引擎的，这个存储引擎和MyISAM有着不同的优势，InnoDB提供事务支持事务，外部键等高级数据库功能，虽然我不是很懂是什么意思，不过我知道的是用MyISAM存储引擎频繁操作数据库，很容易导致数据库锁表，那是一件很抓狂的事情。
必须要在编译mysql的时候加上&#8211;with-plugins=innobase参数


重新编译

cd mysql-5.1.54/
./configure --prefix=/usr/local/mysql --with-extra-charsets=all --enable-thread-safe-client --enable-assembler --with-charset=utf8 --enable-thread-safe-client --with-extra-charsets=all --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase

make &#38;&#38; make install

Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>很多情况下，默认安装的mysql是不支持InnoDB这个存储引擎的，这个存储引擎和MyISAM有着不同的优势，InnoDB提供事务支持事务，外部键等高级数据库功能，虽然我不是很懂是什么意思，不过我知道的是用MyISAM存储引擎频繁操作数据库，很容易导致数据库锁表，那是一件很抓狂的事情。<span id="more-719"></span></p>
<p>必须要在编译mysql的时候加上&#8211;with-plugins=innobase参数</p>
<pre class="brush: php; title: ;">

重新编译

cd mysql-5.1.54/
./configure --prefix=/usr/local/mysql --with-extra-charsets=all --enable-thread-safe-client --enable-assembler --with-charset=utf8 --enable-thread-safe-client --with-extra-charsets=all --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase

make &amp;&amp; make install
</pre>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-let-mysql-support-innodb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux下开启mysql远程数据库</title>
		<link>http://www.imfeng.com/linuxopen-mysql-remote-database/</link>
		<comments>http://www.imfeng.com/linuxopen-mysql-remote-database/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 07:06:42 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[数据库]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=715</guid>
		<description><![CDATA[在文章 mysql开启远程数据库 写了 怎么用命令开启。


grant all PRIVILEGES on *.* to root@’110.110.110.110 identified by ‘123456′;
flush privileges;

其实除此之外,如果还是不能连接，说明，防火墙禁止了，需要执行下面这条语句

iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>在文章 <a href="http://www.imfeng.com/linux-about-mysql-ques/">mysql开启远程数据库</a> 写了 怎么用命令开启。<span id="more-715"></span></p>
<pre class="brush: php; title: ;">

grant all PRIVILEGES on *.* to root@’110.110.110.110 identified by ‘123456′;
flush privileges;
</pre>
<p>其实除此之外,如果还是不能连接，说明，防火墙禁止了，需要执行下面这条语句</p>
<pre class="brush: php; title: ;">
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
</pre>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linuxopen-mysql-remote-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux下面关于mysql相关问题记录</title>
		<link>http://www.imfeng.com/linux-about-mysql-ques/</link>
		<comments>http://www.imfeng.com/linux-about-mysql-ques/#comments</comments>
		<pubDate>Mon, 02 May 2011 09:02:37 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=576</guid>
		<description><![CDATA[首先：如何登陆mysql数据库。
/usr/local/mysql/bin/mysql -u root -p123456
 
然后：如何开启远程数据库。
grant all PRIVILEGES on *.* to root@&#8217;110.110.110.110 identified by &#8216;123456&#8242;;
然后 flush privileges 即时生效。
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>首先：如何登陆mysql数据库。<span id="more-576"></span></p>
<p>/usr/local/mysql/bin/mysql -u root -p123456</p>
<p> </p>
<p>然后：如何开启远程数据库。</p>
<p>grant all PRIVILEGES on *.* to root@&#8217;110.110.110.110 identified by &#8216;123456&#8242;;</p>
<p>然后 flush privileges 即时生效。</p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-about-mysql-ques/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux 忘记mysql密码解决方法</title>
		<link>http://www.imfeng.com/linux-forget-mysql-password/</link>
		<comments>http://www.imfeng.com/linux-forget-mysql-password/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 16:05:16 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=565</guid>
		<description><![CDATA[linux 忘记mysql密码解决方法
1&#62;修改MySQL的登录设置：
# vi /etc/my.cnf  在[MySQLd]的段中加上一句：skip-grant-tables
保存并且退出vi。
2&#62;重新启动MySQLd
3&#62;登录并修改MySQLroot密码


/usr/local/mysql/bin/mysql -u root -p
use mysql;
update user set password =password('') where user ='root';
flush privileges;
quit

4&#62;将MySQL的登录设置修改回来


# vi /etc/my.cnf  


将刚才在[MySQLd]的段中加上的skip-grant-tables删除
保存并且退出vi。
5&#62;重新启动MySQLd
 lnmp
cd /usr/local/mysql/bin
 
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>linux 忘记mysql密码解决方法<span id="more-565"></span></p>
<p>1&gt;修改MySQL的登录设置：</p>
<p># vi /etc/my.cnf  在[MySQLd]的段中加上一句：skip-grant-tables</p>
<p>保存并且退出vi。</p>
<p>2&gt;重新启动MySQLd</p>
<p>3&gt;登录并修改MySQLroot密码</p>
<pre class="brush: php; title: ;">

/usr/local/mysql/bin/mysql -u root -p
use mysql;
update user set password =password('') where user ='root';
flush privileges;
quit
</pre>
<p>4&gt;将MySQL的登录设置修改回来</p>
<pre>
<ol>
<li><span><span># vi /etc/my.cnf  </span></span></li>
</ol>
</pre>
<p>将刚才在[MySQLd]的段中加上的skip-grant-tables删除</p>
<p>保存并且退出vi。</p>
<p>5&gt;重新启动MySQLd</p>
<p><span> lnmp</span></p>
<p><span>cd /usr/local/mysql/bin</span></p>
<p><span> </span></p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-forget-mysql-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>css hack写法</title>
		<link>http://www.imfeng.com/compatible-with-different-browser-css-hack/</link>
		<comments>http://www.imfeng.com/compatible-with-different-browser-css-hack/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 16:14:43 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[css hack]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=547</guid>
		<description><![CDATA[浏览器市场的混乱，给设计师造成很大的麻烦，设计的页面兼容完这个浏览器还得兼容那个浏览器，本来ie6跟ff之间的兼容是很容易解决的。加上个ie7会麻烦点，ie8的出现就更头疼了，原来hack ie7的方法又不能用了，怎么办呢？
枫子编:
正常写法给FF看,*对IE7 IE8,-对IE6
 
第一种方法：
还好，微软提供了这样一个代码：
&#60;meta http-equiv=&#8221;x-ua-compatible&#8221; content=&#8221;ie=7&#8243; /&#62;
把这段代码放到&#60;head&#62;里面，在ie8里面的页面解析起来就跟ie7一模一样的了，所以，基本上可以无视ie8，剩下的代码只需要这样写就可以了
background:#ffc; /*  对firefox有效*/
*background:#ccc; /* 对ie7有效 */
_background:#000; /* 只对ie6有效 */
解释一下吧：
firefox能解析第一段，后面的两个因为前面加了特殊符号“*”和“_”,firefox认不了，所以只认background:#ffc，看到的是黄色；
ie7前两短都能认，以最后的为准，所以最后解析是background:#ccc，看到的是灰色；
ie6三段都能认，而且“_”这个只有ie6能认，所以最后解析是_background:#000，看到的是黑色
阿门！已经是最简单和最好理解的写法了，如果你是google进来的，我可以很负责任的告诉你，这种方法是ok的，我测试过。
ie8的那段兼容7的代码我也测试过了，在我现在的windos 7 测试版所带的ie8是没问题的，以后ie8正式版出来还管不管用就不知道了。
ps：如果你发现按我这样写还是有问题的话，请查看一下你的html头，看看&#60;head&#62;之前的内容是不是这样的标准写法
&#60;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8220;&#62;
&#60;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8220;&#62;
这个是现在比较规范的写法，如果你是用dreamweaver做页面的话，默认也是这种规范的，切记，非这种规范写法的，兼容性不能保证
第二种方法：
要求苛刻的朋友是不愿意在页面头部增加&#60;meta http-equiv=&#8221;x-ua-compatible&#8221; content=&#8221;ie=7&#8243; /&#62;这样一句代码的，因为这样的结果是每个页面都得加。那么要想兼容这几个浏览器还真得想别的办法了。早些天本站发布了一篇《完美兼容ie6,ie7,ie8以及firefox的css透明滤镜》，可能当时测试的疏忽，IE8的兼容性没有解决好，好多朋友回复说用不了。今天抽出些时间，查阅大量资料，终于解决了这个问题了。
以下是兼容IE6/IE7/IE8/FF的写法，注意下面的顺序不可颠倒
margin-bottom:40px;       /*ff的属性*/
margin-bottom:140px\9;    /* IE6/7/8的属性 */
color:red\0;              /* IE8支持 */
*margin-bottom:450px;     /*IE6/7的属性*/
文章出处：标准之路(http://www.aa25.cn/web_w3c/868.shtml)
Here is no comments yet by the time  your rss reader get this, Do you want to be the first [...]]]></description>
			<content:encoded><![CDATA[<p>浏览器市场的混乱，给设计师造成很大的麻烦，设计的页面兼容完这个浏览器还得兼容那个浏览器，本来ie6跟ff之间的兼容是很容易解决的。加上个ie7会麻烦点，ie8的出现就更头疼了，原来hack ie7的方法又不能用了，怎么办呢？<span id="more-547"></span></p>
<p><a href="http://www.imfeng.com/">枫子</a>编:</p>
<p>正常写法给FF看,*对IE7 IE8,-对IE6</p>
<p> </p>
<p>第一种方法：</p>
<p>还好，微软提供了这样一个代码：</p>
<p>&lt;meta http-equiv=&#8221;x-ua-compatible&#8221; content=&#8221;ie=7&#8243; /&gt;<br />
把这段代码放到&lt;head&gt;里面，在ie8里面的页面解析起来就跟ie7一模一样的了，所以，基本上可以无视ie8，剩下的代码只需要这样写就可以了</p>
<p>background:#ffc; /*  对firefox有效*/<br />
*background:#ccc; /* 对ie7有效 */<br />
_background:#000; /* 只对ie6有效 */<br />
解释一下吧：</p>
<p>firefox能解析第一段，后面的两个因为前面加了特殊符号“*”和“_”,firefox认不了，所以只认background:#ffc，看到的是黄色；</p>
<p>ie7前两短都能认，以最后的为准，所以最后解析是background:#ccc，看到的是灰色；</p>
<p>ie6三段都能认，而且“_”这个只有ie6能认，所以最后解析是_background:#000，看到的是黑色</p>
<p>阿门！已经是最简单和最好理解的写法了，如果你是google进来的，我可以很负责任的告诉你，这种方法是ok的，我测试过。</p>
<p>ie8的那段兼容7的代码我也测试过了，在我现在的windos 7 测试版所带的ie8是没问题的，以后ie8正式版出来还管不管用就不知道了。</p>
<p>ps：如果你发现按我这样写还是有问题的话，请查看一下你的html头，看看&lt;head&gt;之前的内容是不是这样的标准写法</p>
<p>&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>&#8220;&gt;<br />
&lt;html xmlns=&#8221;<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>&#8220;&gt;</p>
<p>这个是现在比较规范的写法，如果你是用dreamweaver做页面的话，默认也是这种规范的，切记，非这种规范写法的，兼容性不能保证</p>
<p>第二种方法：</p>
<p>要求苛刻的朋友是不愿意在页面头部增加&lt;meta http-equiv=&#8221;x-ua-compatible&#8221; content=&#8221;ie=7&#8243; /&gt;这样一句代码的，因为这样的结果是每个页面都得加。那么要想兼容这几个浏览器还真得想别的办法了。早些天本站发布了一篇《完美兼容ie6,ie7,ie8以及firefox的css透明滤镜》，可能当时测试的疏忽，IE8的兼容性没有解决好，好多朋友回复说用不了。今天抽出些时间，查阅大量资料，终于解决了这个问题了。</p>
<p>以下是兼容IE6/IE7/IE8/FF的写法，注意下面的顺序不可颠倒</p>
<p>margin-bottom:40px;       /*ff的属性*/<br />
margin-bottom:140px\9;    /* IE6/7/8的属性 */<br />
color:red\0;              /* IE8支持 */<br />
*margin-bottom:450px;     /*IE6/7的属性*/<br />
文章出处：标准之路(<a href="http://www.aa25.cn/web_w3c/868.shtml">http://www.aa25.cn/web_w3c/868.shtml</a>)</p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/compatible-with-different-browser-css-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

