CentOS-based MySQL learning supplement three--create database tables in bulk using the shell

Source: Internet
Author: User

The source of this article: http://blog.csdn.net/u012377333/article/details/47006087

After the introduction of the CentOS-based MySQL learning Supplement two-using the shell to create a database, this article continues to explore the use of shell and MySQL together, I don't know how to quickly create a well-designed database table and add the appropriate basic data after a database design is complete, what I now know is to use shell and SQL scripts to achieve my purpose--fast, multiple, reusable database tables.

Create a SQL script for a database table:

/************************************************************ #Author: Chisj#date:2015.7.22#describe:create Database ' SmartCare ' Table ' sct_province ' *************************************************************/use Smartcare;drop TABLE IF EXISTS ' sct_province '; CREATE TABLE ' sct_province ' (' Provinceid ' int (one) unsigned not NULL auto_increment, ' provincecode ' varchar (one) DEFAULT NULL, ' parentid ' varchar (one) default null, ' provincename ' varchar () default NULL, ' Level ' tinyint (1) default NULL, PRIMARY KEY (' Provinceid ')) Engine=myisam auto_increment=1 DEFAULT Charset=utf8;


Executes the specified directory under allSQL Scripts (specify directories, multiple SQL scripts) for shell scripts:

#!/bin/bash#author:chisj#time:2015.7.22#describe:create Database table#the username of MySQL databaseuser= "root" #The Password of MySQL databasepass= "Dragonwake" #The datebase name would be createddatabase= "SmartCare" location=${pwd}create _TABLE_SCT=CREATE_TABLE_SCT_FOR table_name in ' LS ${location}/${create_table_sct}* ' domysql-u $USER-p$PASS << EOF >/dev/nullsource ${table_name}; Eofif [$?-eq 0]; Thenecho "Create Table ${table_name} success!" Fidone
In fact, there are many ways to create data tables in the shell batch, before they have seen, but do not remember 0.0, visible record is very important yo

So I went through my thinking again: First write the SQL script to create the data table is necessary, you can write all of them in one (personally feel bad), you can also follow a table to write a SQL script (currently I use this method in the city), Then just follow the specified SQL script name in the specified directory, find a SQL script to create the database table, and execute it once.


also gives the CSDN: Shell to create MySQL data table




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

CentOS-based MySQL learning supplement three--create database tables in bulk using the shell

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.