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