How to run the script in mysql. Taking running niuzi. SQL as an example, mysqlniuzi. SQL

Source: Internet
Author: User
Tags mysql command line

How to run the script in mysql. Taking running niuzi. SQL as an example, mysqlniuzi. SQL

Suppose you want to run the Script: F: \ hello world \ niuzi. SQL

Method 1:
In the command line (Database not connected), enter mysql-h localhost-u root-p <F: \ hello world \ niuzi. SQL (note that no quotation marks are required for the path !!).

Method 2:
In the command line (the database is connected, and the prompt is mysql>), enter source F: \ hello world \ niuzi. SQL (note that no quotation marks are required for the path) or \. f: \ hello world \ niuzi. SQL (note that no quotation marks are required for the path)


How does mysql command line tool execute script files?

Method 1:
In the command line (Database not connected), enter mysql-h localhost-u root-p123456 <F: \ hello world \ niuzi. SQL (note that no quotation marks are required for the path !!) Press enter.
Method 2:
In the command line (the database is connected, and the prompt is mysql>), enter source F: \ hello world \ niuzi. SQL (note that no quotation marks are required for the path) or \. f: \ hello world \ niuzi. SQL (note that no quotation marks are required for the path). Press enter.

How to execute a mysql SQL script file

The basic steps are as follows: 1. Create an SQL script file that contains SQL commands. The file contains a series of SQL statements. Each statement ends with a; and the file name is assumed to be ss. SQL, file content example (use "--" to comment): -- create a table create table name (Guid Varchar (38) not null primary key, Title Varchar (255 ),) TYPE = InnoDB; -- add the Statusalter table A add Status TinyInt default '0' in table A; -- create index XX_TaskId_1 on A (Id _) on table _); -- Insert into A (Id, ParentId, Name) values (, 'name'); -- after adding, modifying, and deleting data in Table, you may need to submit the transaction Commit. 2. Execute the SQL script file method 1. Run the cmd command (take windows as an example, unix or linux run in a similar console) in the format: [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 <d: \ test \ ss. SQL Note: 1. If the use database is used in the SQL script file, the-D database option can be ignored. 2. If the bin directory of Mysql contains spaces, you need to 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] 3. If you need to output the execution result to the file, the following mode can be used: D: \ mysql \ bin \ mysql-uroot-p123456-Dtest <d: \ test \ ss. SQL> d: \ dd.txt method 2 enter the mysql console, run the source command 1, enter the mysql console D: \ mysql \ bin \ mysql-uroot-p123456-Dtest2. Execute the SQL script file

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.