Assuming the MySQL user name root password 123456, create a new test data table Utable script as follows:
#!/bin/bash
#mysqlop. Sh
Mysql= "/app/local/mysql/bin/mysql-uroot-p123456"
#sql = "Show Databases"
#sql = "Show tables from Test"
Sql= "CREATE TABLE test.utable (
ID int unsigned auto_increment primary key,
Username varchar (50),
passwd varchar (50)
)"
#sql = "desc test.utable"
#sql = "INSERT into test.utable (USERNAME,PASSWD) VALUES (' User3 ', 321)"
#sql = "SELECT * FROM Test.utable"
#sql = "Delete from test.utable where id=3"
#sql = "Update test.utable set passwd=135 where id=2"
#sql = "DROP table test.utable"
$mysql-E "$sql"
#sh mysqlop.sh
Comment out create statement and continue editing script after new completion
#!/bin/bash
#mysql. Sh
Mysql= "/app/local/mysql/bin/mysql-uroot-p123456"
Case $ in
Select
Sql= "SELECT * from Test.utable"
;;
Delete
Sql= "Delete from test.utable where id=$2"
;;
Insert
Sql= "INSERT into test.utable (USERNAME,PASSWD) VALUES (' $ ', ' $ $ ')"
;;
Update
sql= "Update test.utable set Username= ' $ $ ', passwd=$4 where id= ' $ $ '"
;;
*)
Sql= "SELECT * from Test.utable"
;;
Esac
$mysql-E "$sql"
: X Save exit
#chmod +x mysqlop.sh
The invocation example is as follows:
#./mysqlop.sh Insert User1 321# increase
#./mysqlop.sh Insert User2 312# Increase
#./mysqlop.sh Insert User3 123# Increase
#./mysqlop.sh Insert User4 132# Increase
#./mysqlop.sh Insert User5 213# Increase
#./mysqlop.sh Delete AA Delete
#./mysqlop.sh Update 2 User6 111# change
#./mysqlop.sh select#
#./mysqlop.sh AAA #查
Shell operation MySQL Add and revise check