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