MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
1PLs Company - #1Payday.Loans Agency - Loans online and near me $100-$2500 (Same Day)
Powered by MySQL
 
Home / Client Server Commands / Question No: 93

How to run SQL script files in mysql client?

I have an input file containing multiple SQL statements which I want to execute in one go. Is there is any command in mysql client which can do so?

Answer No: 93

One way to process a script file is by executing it with a SOURCE command from within mysql:

mysql> SOURCE input_file

The file must be located on the client host where you're running mysql. The filename must either be an absolute pathname listing the full name of the file, or a pathname that's specified relative to the directory in which you invoked mysql. For example, if you started mysql on a Windows machine in the C:\mysql directory and your script file is my_commands.sql in the C:\scripts directory, both of the following SOURCE commands tell mysql to execute the SQL statements in the file:

mysql> SOURCE C:\scripts\my_commands.sql;
mysql> SOURCE ..\scripts\my_commands.sql;

The other way to execute a script file is by naming it on the mysql command line. Invoke mysql and use the < input redirection operator to specify the file from which to read query input:

shell> mysql db_name < input_file

If a statement in a script file fails with an error, mysql ignores the rest of the file. To execute the entire file regardless of whether errors occur, invoke mysql with the --force or -f option.

Related MySQL FAQs to the Above FAQ

What-are-MySQL-client-programs What are MySQL client programs?

What-are-MySQL-non-client-utilities What are MySQL non-client utilities?

What-is-mysql-client-program-and-how-to-run-it What is mysql client program and how to run it?

How-to-connect-mysql-client-program-with-MySQL-Server-from-the-command-line How to connect mysql client program with MySQL Server from the command line?

What-is-difference-among-mysqld-mysqladmin-mysqldump-mysqlimport-and-mysqlcheck What is difference among mysqld, mysqladmin, mysqldump, mysqlimport and mysqlcheck?

How-to-check-version-of-the-running-MySQL-Server How to check version of the running MySQL Server?

What-is----compress-or--C What is --compress or -C?

What-is-difference-among---defaults-file---defaults-extra-file-and---no-defaults What is difference among --defaults-file, --defaults-extra-file and --no-defaults?

What-is-difference-between-g-and-G-characters-in-mysql-client-program What is difference between \g and \G characters in mysql client program?

How-to-execute-statement(s)-directly-from-the-command-line How to execute statement(s) directly from the command line?

How-to-cancel-the-statement-in-mysql-client-program How to cancel the statement in mysql client program?

What-is-difference-between-Interactive-Mode-and-Batch-Mode-of-mysql-client What is difference between Interactive Mode and Batch Mode of mysql client?

How-to-execute-the-entire-script-file-regardless-of-errors-occurrence How to execute the entire script file regardless of errors occurrence?

What-does-STATUS-command-in-mysql-client What does STATUS command in mysql client?

How-to-know-MySQL-system-variables How to know MySQL system variables?

What-does-MySQL-use-its-port-by-default What does MySQL use its port by default?

What-does---safe-updates-option-in-mysql What does --safe-updates option in mysql?

What-is-sql-mode-in-MySQL-and-how-can-we-set-it What is sql mode in MySQL and how can we set it?

How-to-check-the-MySQL-running-mode How to check the MySQL running mode?

About FAQs: Recently Added FAQs

About MySQL FAQs: Site Map | Bookmark Us | Recommend this Site to Your Friend | Contact Us

Useful Links: Wikipedia.org | Oracle.com | w3schools.com | www.php.net | Github.com

© 2023  www.mysqlfaqs.net
All rights reserved.