<?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>某人的栖息地 &#187; sql</title>
	<atom:link href="http://www.ooso.net/tag/sql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ooso.net</link>
	<description>Linux + Apache + Mysql + Php + Flash</description>
	<lastBuildDate>Thu, 19 Jan 2012 01:21:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>混合使用SQL和shell命令</title>
		<link>http://www.ooso.net/archives/439</link>
		<comments>http://www.ooso.net/archives/439#comments</comments>
		<pubDate>Tue, 01 Jul 2008 01:19:57 +0000</pubDate>
		<dc:creator>Volcano</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/439</guid>
		<description><![CDATA[mysql下可以用批处理模式运行SQL，比如:
shell&#62; mysql -h host -u user -p &#60; batch-file.sql
Enter password: ********
但是平常往往需要在执行sql的同时，运行一些shell脚本进行进一步计算，保存日志之类的。这个可以靠mysql的system命令来实现，例如：

				<span class="readmore"><a href="http://www.ooso.net/archives/439" title="混合使用SQL和shell命令">阅读全文（603字）</a></span>]]></description>
			<content:encoded><![CDATA[<p>mysql下可以用批处理模式运行SQL，比如:</p>
<pre><code>shell&gt; mysql -h host -u user -p &lt; batch-file.sql
Enter password: ********</code></pre>
<p>但是平常往往需要在执行sql的同时，运行一些shell脚本进行进一步计算，保存日志之类的。这个可以靠<a href="/?tag=mysql">mysql</a>的system命令来实现，例如：</p>
<pre><code># Mixing shell commands and SQL queries in batch mode- demo script
use test;
#INSTALL PLUGIN example SONAME 'ha_example.so'; #Ignore statement
system cp /tmp/mysqld.trace logs/init.trace # Shell commands prefixed with a 'system'
create table new4(num integer) engine=EXAMPLE;
system cp /tmp/mysqld.trace logs/after_create.trace # Shell commands prefixed with a 'system'
system diff logs/init.trace logs/after_create.trace # Shell commands prefixed with a 'system'</code></pre>
<h3>注意</h3>
<ul>
<li>system命令只在类unix操作系统上有效。</li>
<li>可以在存储过程中使用system。</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ooso.net/archives/439/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>在命令行里执行mysql的sql</title>
		<link>http://www.ooso.net/archives/429</link>
		<comments>http://www.ooso.net/archives/429#comments</comments>
		<pubDate>Mon, 23 Jun 2008 03:05:39 +0000</pubDate>
		<dc:creator>Volcano</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.ooso.net/?p=429</guid>
		<description><![CDATA[平常执行sql，需要登录到mysql的shell下，然后再执行。比如：
$ /usr/bin/mysql -u root
mysql&#62; select * from users;
但是如果写一点简单的脚本，也可以在命令行下直接运行sql并显示结果，比如：

				<span class="readmore"><a href="http://www.ooso.net/archives/429" title="在命令行里执行mysql的sql">阅读全文（204字）</a></span>]]></description>
			<content:encoded><![CDATA[<p>平常执行sql，需要登录到<a href="/?tag=mysql">mysql</a>的shell下，然后再执行。比如：</p>
<pre><code>$ /usr/bin/mysql -u root
mysql&gt; select * from users;</code></pre>
<p>但是如果写一点简单的脚本，也可以在命令行下直接运行sql并显示结果，比如：</p>
<pre><code>$ cat executemysql.sh
#!/bin/sh

qry=$1;

echo "Executing the following query"
echo "$qry"

mysql -u root &lt;&lt; eof
$qry
eof</code></pre>
<p>运行一下:</p>
<pre><code>$ ./executemysql.sh "select id,name,age from test.users limit 2"
Executing the following query
select id,name,age from test.users limit 2
id name age
3 john 20
4 tom 21</code></pre>
<p>原文：<a href="http://unstableme.blogspot.com/2008/06/execute-mysql-from-bash-script.html">Execute mysql from bash script</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ooso.net/archives/429/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

