国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

Shell腳本中執行sql語句操作MySQL數據庫的幾個辦法

2024-07-24 12:32:25
字體:
來源:轉載
供稿:網友
        實驗如下:
      [root@idb1 ~]# more /etc/issue
      CentOS release 6.5 (Final)
      Kernel /r on an /m
  
mysql> show variables like 'version';
+---------------+------------+
| Variable_name | Value      |
+---------------+------------+
| version       | 5.6.27-log |
+---------------+------------+
1 row in set (0.00 sec)
  
1、將SQL語句直接嵌入到shell腳本文件中
     [root@idb1 ~]# cat shell_example01.sh
     #!/bin/bash
     # Define log
TIMESTAMP=`date +%Y%m%d%H%M%S`
LOG=call_sql_${TIMESTAMP}.log
echo "Start execute sql statement at `date`." >>${LOG}
  
[root@idb1 ~]# chmod +x shell_example01.sh
 
[root@idb1 ~]# sh shell_example01.sh
Warning: Using a password on the command line interface can be insecure.
Logging to file '/tmp/temp.log'
+------+-------+
| id   | val   |
+------+-------+
|    1 | jack  |
|    2 | robin |
|    3 | mark  |
+------+-------+
Outfile disabled.
 
 
2、 shell腳本中MySQL提示符下調用SQL命令例子:
[root@idb1 ~]# cat shell_example02.sh
#!/bin/bash
mysql -umdba -pdsf0723 <<EOF
source /root/temp.sql;
select current_date();
delete from tempdb.tb_tmp where id=3;
select * from tempdb.tb_tmp where id=2;
EOF
exit
 
 
[root@idb1 ~]# sh shell_example02.sh
Warning: Using a password on the command line interface can be insecure.
Logging to file '/tmp/temp.log'
id      val
1       duansf
2       liuyb
3       jack
Outfile disabled.
current_date()
2017-03-14
id      val
2       liuyb

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 潞西市| 文安县| 台南市| 岑巩县| 拉萨市| 柳州市| 澄江县| 柏乡县| 宜宾市| 松阳县| 吉安市| 长沙县| 礼泉县| 吕梁市| 古蔺县| 竹溪县| 清丰县| 咸宁市| 连云港市| 洪泽县| 莫力| 松桃| 从化市| 新巴尔虎右旗| 大足县| 寻乌县| 双流县| 合作市| 东辽县| 石门县| 台中市| 嘉义市| 定日县| 灵丘县| 平乡县| 巴塘县| 客服| 昭平县| 通榆县| 潮安县| 秀山|