[MySQL FAQ]系列 -- 从dump文件中抽取部分库表

其实很简单,就是利用正则表达式,从文件中抽取,可以用awk或sed,例如:

1. 抽取数据库 imysql_1 的全部SQL语句

#假设数据库 imysql_1 的下一个是 imysql_2 
DBNAME1="imysql_1"
DBNAME2="imysql_2"
sed -n “/^-- Current Database: \`$DBNAME1\`/,/^-- Current Database: \`$DBNAME2\`/p”  imysql_20100601.sql

 

2. 抽取数据表 user_base 的全部SQL语句

#假设数据表 user_base 的下一个是 user_detail
DBTAB1="user_base"
DBTAB2="user_detail"
sed -n “/^-- Table structure for table \`$DBTAB1\`/,/^-- Table structure for table \`$DBTAB2\`/p”  imysql_20100601.sql

 

上面只是个例子,正则表达里面的表达式可以根据各自导出文件的内容进行修改

回复

此内容将保密,不会被其他人看见。
  • 允许的 HTML 标签: <a> <b> <address> <blockquote> <br> <caption> <center> <code> <dd> <del> <div> <dl> <dt> <em> <font> <h2> <h3> <h4> <h5> <h6> <hr> <i> <img> <li> <ol> <p> <pre> <span> <strong> <sub> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <u> <ul> <tr>
  • 行和段被自动切分。
  • 网页地址和电子邮件地址将会被自动转换为链接。

更多格式化选项信息

随机验证
本功能用于防止垃圾信息
在输入框中输入图片上的字符(注意大小写)