Create databases/tables in batches using Linux shell
The Shell script is as follows:
- # Create database and table
- HOST ='Localhost'
- PORT ='123'
- USER ='Root'
- PWD =''
- DBNAME ='Top123'
- TABLENAME ='Gametop800'
- Mysql_login =''
- Mysql_create_db =''
- Mysql_create_table =''
- Function mysql_create (){
- Echo"Login mysql $ HOST: $ PORT ..."
- Mysql_login ="Sudo mysql-h $ HOST-P $ PORT-u $ USER"# Mysql-h host-P port-u root-p pwd
- Echo | $ {mysql_login}
- If[$? -Ne0]; Then
- Echo"Login mysql $ {HOST }:$ {PORT} failed .."
- Exit1
- Fi
- Echo"Create database $ DBNAME ..."
- Mysql_create_db ="Create database if not exists $ DBNAME"
- Echo $ {mysql_create_db} | $ {mysql_login}
- If[$? -Ne0]; Then
- Echo"Create db $ {DBNAME} failed .."
- Exit1
- Fi
- Echo"Create table $ TABLENAME ..."
- Mysql_create_table = "create table $ TABLENAME (
- Id char (50)NotNull,
- Top int,
- Name char (100),
- Category char (50),
- Rating float,
- Ratingcount char (20),
- Download char (30),
- Price char (20),
- Publishdate char (20),
- Version char (40),
- Filesize char (40),
- RequireAndroid char (40),
- Contentrating char (40),
- Country char (10),
- Dtime datetimeNotNull,
- Primary key (id, dtime)
- )"
- Echo $ {mysql_create_table} | $ {mysql_login }$ {DBNAME}
- If[$? -Ne0]; Then
- Echo"Create table $ {TABLENAME} fail ..."
- Exit1
- Fi
- Echo"Create table $ {TABLENAME} success! "
- }
After the script is executed, the result is as follows:
MySQL slave common operation commands:
Show Database
ShowDatabases;
Switch Database
UseTop123;
Show database tables
ShowTables;
Modify primary key
Alter table gametop800 add primary key (Id);
Delete primary key
Alter table gametop800DropPrimary 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: