Solved

mysql command line input file?  (similar to osql -i  ?)

Posted on 2010-09-10
1
1,364 Views
Last Modified: 2012-06-21
I'm used to running osql against microsoft sql server and one of the options I often use is -i <file> which allows me to build a command file and then run it by name with a single osql command.

Is there something like that in mysql?

I see there is INFILE but that appears to me to be data input, not command input.

Is there some way I can execute a command like:

mysql -u root --password=xxxx -i <command input file>

where the <command input file> is read and all the sql commands in that file are run?

Thanks.

0
Comment
Question by:gateguard
1 Comment
 
LVL 6

Accepted Solution

by:
Gunter17 earned 500 total points
ID: 33649580
From the mysql man page.

EXECUTING SQL STATEMENTS FROM A TEXT FILE
       The mysql client typically is used interactively, like this:

           shell> mysql db_name

       However, it is also possible to put your SQL statements in a file and
       then tell mysql to read its input from that file. To do so, create a
       text file text_file that contains the statements you wish to execute.
       Then invoke mysql as shown here:

           shell> mysql db_name < text_file

       If you place a USE db_name statement as the first statement in the
       file, it is unnecessary to specify the database name on the command
       line:

           shell> mysql < text_file

       If you are already running mysql, you can execute an SQL script file
       using the source command or \.  command:

           mysql> source file_name
           mysql> \. file_name
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question