Shell operation MySQL Add and revise check

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.