Shell operations on mysql Databases

Source: Internet
Author: User

Shell to operate mysql database mysql-hhostname-Pport-uusername-ppassword-e related mysql SQL statements, you can operate mysql in shell without running mysql at a mysql prompt. #! /Bin/bash HOSTNAME = "192.168.111.84"; # Database Information PORT = "3306"; USERNAME = "root"; PASSWORD = ""; DBNAME = "test_db_test "; # Database Name TABLENAME = "test_table_test "; # Name of the table in the database # create database create_db_ SQL = "create database IF NOT EXISTS $ {DBNAME}" mysql-h $ {HOSTNAME}-P $ {PORT}-u $ {USERNAME} -p $ {PASSWORD}-e "$ {create_db_ SQL}" # create a table create_table_ SQL = "create table IF NOT EXISTS $ {TABLENAME} (namevarchar (20 ), id int (11) default 0) "mysql-h $ {HOSTNAME}-P $ {PORT}-u $ {USERNAME}-p $ {PASSWORD }$ {DBNAME}-e" $ {create_table_ SQL} "# insert data insert_ SQL = "insertinto $ {TABLENAME} values ('billchen ', 2) "mysql-h $ {HOSTNAME}-P $ {PORT}-u $ {USERNAME}-p $ {PASSWORD }$ {DBNAME}-e" $ {insert_ SQL} "# Query select_ SQL = "select * from $ {TABLENAME}" mysql-h $ {HOSTNAME}-P $ {PORT}-u $ {USERNAME}-p $ {PASSWORD} $ {DBNAME} -e "$ {select_ SQL}" # update data update_ SQL = "update $ {TABLENAME} set id = 3" mysql-h $ {HOSTNAME}-P $ {PORT}-u $ {USERNAME}-p $ {PASSWORD }$ {DBNAME}-e "$ {update_ SQL}" mysql-h $ {HOSTNAME}-P $ {PORT}-u $ {USERNAME} -p $ {PASSWORD }$ {DBNAME}-e "$ {select_ SQL}" # e_ SQL = "deletefrom $ {TABLENAME}" mysql-h $ {HOSTNAME}-P $ {PORT}-u $ {USERNAME}-p $ {PASSWORD }$ {DBNAME}-e "$ {delete_ SQL}" mysql-h $ {HOSTNAME}-P $ {PORT} -u $ {USERNAME}-p $ {PASSWORD }$ {DBNAME}-e "$ {select_ SQL }"

Related Article

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.