Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-10
1
Medium Priority
?
1,422 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 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

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…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

721 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