Solved

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

Posted on 2010-09-10
1
1,316 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now