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 create a well-designed database table and add the corresponding basic data after a database has been designed, what I now know is to use shell and SQL scripts to achieve my purpose--high-speed, 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;


Run all under the specified folderSQL Scripts (Specify folders, 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 a lot of ways that the shell can create data tables in batches, as seen before. Unfortunately not remember 0.0, the visible record is very important yo

So I did it again according to my thinking: first, it is necessary to write the SQL script to create the data table, to write all of them in one (personally think bad), but also to write a SQL script according to a table (this is the way I am doing in the city today), Then it is in the specified folder following the specified SQL script name to traverse. Locate a SQL script that creates a database table, and then run it once.


the same gives the CSDN: Shell to create MySQL data table




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.