Mysql command file

Source: Internet
Author: User

Mysql command file

1. Create an SQL script file containing SQL commands

The file contains SQL statements of some columns. Each statement ends with a;. The file content is as follows:

-- Create a table and use "--" to annotate it

Create table Name

(

Guid Varchar (38) not null primary key,

Title Varchar (255 ),

) TYPE = InnoDB;

-- Add the Status field to Table.

Alter table A add Status TinyInt default '0 ';

-- Create an index on Table

Create index XX_TaskId_1 on A (Id _);

-- Add A record to Table

Insert into A (Id, ParentId, Name) values (1, 0, 'name ');

-- After adding, modifying, and deleting data, you may need to submit a transaction.

Commit;

2. Execute the SQL script file

Method 1 run the cmd command (in windows, unix or Linux, in its console)

[MySQL bin directory] \ mysql-u user name-p password-D database <[full name of the SQL script file path], example:

D: \ mysql \ bin \ mysql-uroot-p123456-Dtest

Note:

A. If the use database is used in the SQL script file, the-D database option can be ignored.

B. If the bin directory of Mysql contains spaces, use "" to include, for example, "C: \ Program Files \ mysql \ bin \ mysql "-u user name-p password-D database <[full name of the SQL script file path]

Method 2: log on to the mysql console and run the source command.

Mysql> source [full name of the SQL script file path] Or Mysql> \. [full name of the SQL script file path], for example:

Source d: \ test \ ss. SQL or \. d: \ test \ ss. SQL

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.