国产探花免费观看_亚洲丰满少妇自慰呻吟_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

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长葛市| 清徐县| 赞皇县| 溧水县| 棋牌| 璧山县| 扬州市| 朝阳区| 盈江县| 南昌县| 左权县| 大连市| 宁陕县| 宾川县| 扶余县| 隆尧县| 清徐县| 嘉黎县| 莱州市| 新龙县| 乐清市| 隆子县| 通海县| 萨迦县| 英山县| 洞口县| 晋江市| 呼伦贝尔市| 吐鲁番市| 永康市| 故城县| 岐山县| 西乌珠穆沁旗| 凌海市| 望城县| 济阳县| 勐海县| 奉贤区| 武汉市| 乌鲁木齐市| 门源|