前幾天分享了shell字符串操作,數組操作等,接下來回歸到項目,進行數據庫操作。按照一般情況來說,shell連接數據庫基本上都是DB使用的,因為需要運行大量的sql啊什么的,所以都會封裝到shell中來進行操作。話不多說,給大家看一個實例,基本上就差不多完事了:
#!/bin/bash
mysql -uroot -proot <<EOF show databases; use super; insert into chains(name) values("renyuz"); insert into chains(name) value("wl"); select * from chains; EOF
運行結果就是:
Database information_schema cms dedecms kd mysql performance_schema project_manager super supers test tests id name 9 wl 8 renyuz 10 renyuz 11 wl 12 renyuz 13 wl 14 renyuz 15 wl
大家可以創建一個表試一下,其中呢,EOF是開始運行和結束運行sql的一種標識。
OK,今天的分享很簡單,到這里就結束了,各位勿噴哈。。。。。。
原文鏈接:https://blog.csdn.net/luyaran/article/details/79396216