Shell script operation MySQL database, using the MySQL-e parameter can perform various types of SQL (create, delete, add, delete, change, check) and other operations

Source: Internet
Author: User

MYSQL-HHOSTNAME-PPORT-UUSERNAME-PPASSWORD-E mysql-related SQL statements without running MySQL at the prompt of MySQL, which means you can manipulate MySQL in the shell.

#!/bin/Bashhostname="192.168.111.84"#数据库信息PORT="3306"USERNAME="Root"PASSWORD=""DBNAME="test_db_test"#数据库名称TABLENAME="test_table_test"#数据库中表的名称

Create a database

Create_db_sql="CREATE database IF not EXISTS ${dbname}"-h${hostname}  -p${ PORT}  -u${username}-p${password}-e"${create_db_sql}"

Create a table

Create_table_sql="CREATE table IF not EXISTS ${tablename} (  name varchar), ID int (one) default 0) "  -h${hostname}  -p${port}  -u${username}-p${password} ${dbname}-e"${create_table_sql }"

Inserting data

Insert_sql="insert INTO ${tablename} values (' Billchen ', 2)'-h${hostname}  - P${port}  -u${username}-p${password} ${dbname}-e"${insert_sql}"

Inquire

Select_sql="select * from ${tablename}"-h${hostname}  -p${port}  -u${username}-p${password} ${dbname}-e"${select_sql}"

Update data

Update_sql="update ${tablename} set id=3"-h${hostname}  -p${port}  -u${ USERNAME}-p${password} ${dbname}-e"${update_sql}"-h${hostname}  - P${port}  -u${username}-p${password} ${dbname}-e"${select_sql}"

Delete data

Delete_sql="delete from ${tablename}"-h${hostname}  -p${port}  -u${ USERNAME}-p${password} ${dbname}-e"${delete_sql}"-h${hostname}  -p${ PORT}  -u${username}-p${password} ${dbname}-e"${select_sql}"



Shell script operation MySQL database, using the MySQL-e parameter can perform various types of SQL (create, delete, add, delete, change, check) and other operations

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.