Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assistance using "command" files to perform SQL commands

Status
Not open for further replies.

pklocke

MIS
Sep 14, 1999
1
US
I have been using MySQL for about 24 hours, so I apologize in advance for my "newbie-ness."<br>
<br>
I am sitting at a mysql prompt inside the client program, trying to figure out how to pass a command file I have edited with the \e (vi) command. I have the file created whereing I am simply trying to create a simple table.<br>
<br>
Now, the problem: How do I pass this command file to mysql?<br>
<br>
I have tried:<br>
<br>
mysql&gt; run &lt;command-file&gt;<br>
<br>
mysql&gt; @commandfile<br>
<br>
mysql&gt; &lt;command-file&gt;<br>
<br>
And other combinations and permutations to know avail. I could not find anything in the documentation relating to this (but then I am not sure what term they use for what I am calling "command files."<br>
<br>
Ideas? THANKS!<br>
<br>
pklocke
 
Create a file with the SQL commands that you wish to run. Then run...

mysql database_name < text_file

...where db_name is the name of your database that the commands should act on, and text_file is the path and name to file containing the SQL commands.

You can also start your text file with USE db_name statement. In this case, you do not need to specify the database name on the command line...

mysql < text_file

Hope it helps. :)
Dave Vickers.
 
Well, to be specific, you should also include the mysql username/hostname combination, if necessary:

Code:
msyql -u username -h hostname -p databasename < file.sql

The -p option means you will be prompted on the command line for the password. If you include the password right after the -p with no spaces (-pPassword), then you will not be prompted for the password.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top