免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2094 | 回复: 0
打印 上一主题 下一主题

shellsql连接mysql [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-03 17:24 |只看该作者 |倒序浏览

shell脚本不能实现mysql的表锁,因为该锁表语句是基于session的,会话断开即解锁。
借助shellsql工具可以解决这个问题:
http://www.edlsystems.com/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。






本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/61187/showart_2016520.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP