SQL scripts are SQL statements that contain one or more SQL commands, and we can put these SQL scripts in a text file (which we call "SQL script files") and execute the SQL script file with the relevant commands. The basic steps are as follows:
1. Create a SQL script file containing SQL commands
The file contains a few columns of SQL statements, each ending with A; end, the file content example is as follows:
--Create a table and annotate with "--"
CREATE TABLE Table name
(
Guid Varchar ($) NOT null primary key,
Title Varchar (255),
) Type=innodb;
--Add field status to Table A
ALTER TABLE A add Status TinyInt default ' 0 ';
--Create an index on table a
Create INDEX xx_taskid_1 on A (ID_);
--Add a record to table a
Insert into A (Id,parentid, name) VALUES (1, 0, ' name ');
--After adding, modifying, and deleting data, it is possible to commit a transaction
Commit;
2. Execute SQL script file
Method one executes with the cmd command (under Windows, UNIX or Linux under its console)
"MySQL Bin directory" \mysql–u user name –p password –d database < "SQL script file path full name" Example:
D:\mysql\bin\mysql–uroot–p123456-dtest<d:\test\ss.sql
Attention:
A, if the use database is used in a SQL script file, the-d database option can be ignored
B, if "MySQL Bin directory" contains spaces, you need to use "" "include, such as:" C:\Program files\mysql\bin\mysql "–u username –p password –d database <" SQL script file path full name "
method Two after entering MySQL console, use the source command to execute
Mysql>source "path full name of SQL script file" or mysql>\. "Path full name of SQL script file", example:
source D:\test\ss.sql or \. D:\test\ss.sql
-
Top
-
4
-
Step
-
1
To create a SQL script file that contains SQL commands