MySQL command operations (Linux)

Source: Internet
Author: User

Create databases/tables in batches using Linux shell

The Shell script is as follows:

# Create database and table <br/> HOST = 'localhost' <br/> PORT = '000000' <br/> USER = 'root' <br/> PWD ='' <br/> DBNAME = 'top123' <br/> TABLENAME = 'gametop800' </p> <p> mysql_login = ''<br/> mysql_create_db ='' <br/> mysql_create_table = ''</p> <p> function mysql_create () {<br/> echo "login mysql $ HOST: $ PORT... "<br/> mysql_login =" sudo mysql-h $ HOST-P $ PORT-u $ USER "# mysql-h host-P port-u root-p pwd <br/> echo | $ {Mysql_login} <br/> if [$? -Ne 0]; then <br/> echo "login mysql $ {HOST }:: {PORT} failed .. "<br/> exit 1 <br/> fi </p> <p> echo" create database $ DBNAME... "<br/> mysql_create_db =" create database if not exists $ DBNAME "<br/> echo $ {mysql_create_db} |$ {mysql_login} <br/> if [$? -Ne 0]; then <br/> echo "create db $ {DBNAME} failed .. "<br/> exit 1 <br/> fi </p> <p> echo" create table $ TABLENAME... "<br/> mysql_create_table =" create table $ TABLENAME (<br/> id char (50) not null, <br/> top int, <br/> name char (100), <br/> category char (50), <br/> rating float, <br/> ratingcount char (20 ), <br/> download char (30), <br/> price char (20), <br/> publishdate char (20), <br/> version ch Ar (40), <br/> filesize char (40), <br/> requireandroid char (40), <br/> contentrating char (40 ), <br/> country char (10), <br/> dtime datetime not null, <br/> primary key (id, dtime) <br/>) "</p> <p> echo $ {mysql_create_table} | $ {mysql_login }$ {DBNAME} <br/> if [$? -Ne 0]; then <br/> echo "create table $ {TABLENAME} fail... "<br/> exit 1 <br/> fi </p> <p> echo" create table $ {TABLENAME} success! "<Br/>}

After the script is executed, the result is as follows:

MySQL slave common operation commands:

Show Database

Show databases;

Switch Database
Use top123;

Show database tables

Show tables;

Modify primary key

Alter table gametop800 add primary key (id );

Delete primary key

Alter table gametop800 drop primary key;

Add composite primary key

Alter table gametop800 add primary key (id, dtime );

If you are interested, you can use more complex syntaxes such as awk, cut, paste, regular expressions, and database operations to complete MySQL database operations.

The following describes how to capture webpages, extract features, extract information, summarize results, and insert data into databases in batches for permanent storage.

Example:

Recommendation reference:

Summary of common MySQL database commands

Mysql Data Type

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.