[Mysql] shell runs mysql SQL statement bitsCN.com
[Mysql] SQL statement used by shell to run mysql
Shell itself is a scripting language, so it cannot connect to the database through APIs like java. Shell still needs to execute SQL statements by using some running scripts of mysql. It is clear that mysql must be installed on the machine first.
You can use the mysql/bin/mysql script to run SQL statements in the format of mysql-hhost-Pport-uusername-ppassword database-e "SQL". The following is the shell code.
[Plain] #! /Bin/sh bin =/usr/local/mysql/bin username = root password = mysql = $ bin/mysql hostname = localhost port = 3306 database = loongdisk table = userio if [" $ password "=" "]; then inputpwd = "" else inputpwd =-p $ password fi # year head = $ database. $ {table} _ month echo $ head SQL = "alter table $ head add column login int (10) unsigned not null default 0 "$ mysql-h $ hostname-P $ port-u $ username $ inputpwd $ database-e" $ SQL"
BitsCN.com