[Mysql] SQL statement used by shell to run mysql

Source: Internet
Author: User

[Mysql] shell runs mysql SQL statement 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"

 


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.