Solved

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

Posted on 2010-09-10
1
1,380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
two ways encryption with php 3 53
SubQuery link 4 59
Survey branching tutorial 11 78
embadded search engine in website 4 47
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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