Under the Linux platform, in order to avoid each operation of the database (MySQL) into the MySQL command mode, you can use the shell command to manipulate the database directly.
first, write directly SQL Statement
If [$#-ne 1]
Then
echo "Please enter the SQL statement to be run"
Exit-1
Fi
Mysql-dmysql-uroot-p123456abcd-e "$"
-D Specify the database name
-U Specify database user name
-P Specify Database password
-e Specifies the SQL statement to run
Second, the script mode of operation
If [$#-ne 1]
Then
echo "Please enter the SQL statement to be run"
Exit-1
Fi
Cat $ | Mysql-dmysql-uroot-p123456abcd
$ specifies the SQL statement script to run
Iii. examples
#!/bash/sh
Hostname= "localhost"
Username= "Root"
password= "Root"
Dbname= "student_db"
Tablename= "Stu"
show_db= "Show Database"
mysql–h${HOSTNAME}–u ${USERNAME}-p${PASSWORD}–e "${show_db}"
tablename_new=${TABLENAME}_ ' date ' +%y_%m_%d "'
Create_table_sql= "CREATE table if Notexists ${tablename_new} (id int (5) NOT null primary key)"
mysql–h${HOSTNAME}–u ${USERNAME}-p${PASSWORD}–e "${Create_table_sql}"
If [$ = 0]; Then
echo "Create yes"
Fi
Using the shell to manipulate MySQL