Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2451384
  • 博文数量: 540
  • 博客积分: 11289
  • 博客等级: 上将
  • 技术积分: 6160
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-11 20:27
个人简介

潜龙勿用,见龙在田

文章分类

全部博文(540)

文章存档

2018年(2)

2013年(5)

2012年(24)

2011年(104)

2010年(60)

2009年(217)

2008年(128)

分类: Mysql/postgreSQL

2009-08-03 17:24:23

shell脚本不能保持mysql的表锁,因为该锁表语句是基于session的,会话断开即解锁。

借助shellsql工具可以解决这个问题:

 

下载后安装:

./install.sh

B

 

1.3 - shmysql

This initiates a MySQL connection. The syntax is....

        shmysql connectarg [connectarg] ...

The connectarg(s) are concatonated together separated by spaces. So for example, the following is perfectlly legal....

        shmysql dbname=test user=myuser

which does the same thing as

        shmysql "dbname=test user=myuser"

Either way, the arguments of the engne take the form of name=value where name is one of the following. Most have sensible defaults.

host The host name or IP address of the server
port The TCP port number to connect to on the server
dbname The database name
user The user name for the connection
password The password for the user
socket The name of the UNIX socket if applicable
flag Usually not defined or zero, but can be used in special circumstances, see the documentation in MySQL for further information.

If you are using the password assignment in the connection then you should use the "password=mysecret" string as a separate parameter. The reason for this is that "shpostgres" will detect it and blank it out in the process table so someone else doing a "ps" cannot see it.

用法举例:

HANDLE=`shmysql user=root password=12345678 dbname=test`

#执行结果是一串数字

 

shsql $HANDLE "flush tables with read lock"

#执行sql语句,只能同时发布执行一条sql语句,如果要执行多个sql语句,执行多次shsql即可;并且不支持system调用系统命令

 

shsql $HANDLE "SQL statement"

...

 

shsql $HANDLE "unlock tables"

 

shsqlend $HANDLE

#结束本次mysql connection,释放$HANDLE

 

更具体的例子请看本人写的LVM snapshot mysql backup shell script。

 

 

 

 

阅读(2161) | 评论(0) | 转发(0) |
0

上一篇:Mysql中limit的用法详解

下一篇:数据库事务

给主人留下些什么吧!~~