shell脚本中操作mysql

1, mysql -e

select_sql="select count(distinct id) from tb_test"
num=$(mysql -s -h$host -u$user -p$passwd $dbname -e "$register_sql")

2, mysqldump导出mysql数据

#!/bin/bash
#变量定义
host="127.0.0.1"
user="root"
passwd="123456"
dbname="test"
tablename="tb_test"
mysqldump -u$user -p$passwd -h$host $dbname  $tablename --where "id > 1 and id < 1000"  > 1.sql

3, mysql直接登陆数据库

#!/bin/bash
user="user"
passwd="password"

host="192.168.0.1"

mysql -h$host  -u$user -p$passwd db 

 

发表评论

邮箱地址不会被公开。