剛寫的乙個使用shell運算元據庫

2021-09-30 15:29:50 字數 2173 閱讀 5799

#!/bin/bash

log='sql_insert_one.sh.log' #定乙個日誌檔案便於我們定位bug

if [ ! -e $log ]; then #如果日誌檔案不存在就新建乙個

touch $log

fidate=$(date "+%y-%m-%d__%h:%m:%s") #記錄列印日誌的時間

echo >> $log

echo "***************== $date ***************=" >> $log

# mysql database and table to create

host='10.10.10.21'

port='3306'

user='root'

pwd='123456'

dbname="mysql" #資料庫名稱

tablename="test_table_test" #資料庫中表的名稱

mysql_login="mysql -h $host -p $port -u $user -p$pwd" #連線資料庫

mysql_create_db=''

mysql_create_table=''

mysql_insert_sql=''

function mysql_insert() -e "use $dbname; $mysql_insert_sql"

if [ $? -ne 0 ] ;then

echo "insert data faild" >>$log

else

echo "insert data sucess" >>$logfi}

function mysql_create() #判斷資料庫是否連線成功

if [ $? -ne 0 ]; then

echo "login mysql $:$ failed.." >>$log

exit 1

else

echo "login mysql $:$ success!" >> $log

fiecho "create database $dbname ..." >> $log #建立資料庫

mysql_create_db="create database if not exists $dbname"

echo $ | $

if [ $? -ne 0 ]; then

echo "create db $ failed.." >> $log

else

echo "create db $ success!" >> $log

fiecho "create table $tablename ..." >> $log #建立表

mysql_create_table="create table $tablename (

ur_id int(11) not null auto_increment,

visit_user_id int(11) not null default '0',

visit_user_kind char(1) not null default '1',

res_user_id int(11) not null default '0',

res_id int(11) not null default '0',

ur_createtime char(14) not null default '00000000000000',

ur_ip varchar(15) not null default '',

primary key (ur_id),

key idx_visituserid_resid (visit_user_id,res_id),

key idx_resuserid_createtime (res_user_id,ur_createtime)

) engine=myisam auto_increment=1168783 default charset=gbk"

echo $ | $ $

if [ $? -ne 0 ]; then

echo "create table $ fail..." >> $log

else

echo "create table $ success!" >> $logfi}

mysql_create #呼叫建立資料庫的函式

mysql_insert #呼叫插入資料的函式

運算元據庫的乙個類

code using system using system.data using system.configuration using system.web using system.web.security using system.web.ui using system.web.ui.webc...

乙個運算元據庫通用幫助類

dbhelper類 using system using system.collections.generic using system.linq using system.text using system.configuration using system.data using system....

自己剛寫的乙個 file check 的SHELL

很高興能分享我的對檔案檢查的shell bin bash dir root filelist a.txt b.txt c.txt d.txt for file in filelist do if f file then echo the file is not exited else echo go...