潜龙勿用,见龙在田
全部博文(540)
分类: 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。