PDA

View Full Version : how do I execute .sql files?



james438
12-05-2007, 10:41 PM
How do you run a file with an sql extension using mysqladmin? I figure this should be easy, but I am not that familiar with the mysqladmin program the one that has starfield technologies logo in the top left corner.

james438
12-06-2007, 12:00 AM
meh, I got lazy and just went to the sql query section and pasted the contents of the query document into it. It works just fine that way, but I figure there is a way I could just access the file itself and execute it. It does not need to be done through mysqladmin. Any ol way will do :)

Twey
12-06-2007, 09:19 AM
Pipe it into mysql.

Shotgun Ninja
12-06-2007, 05:25 PM
LOAD FROM INFILE "page.sql"

(Please correct any mistakes)

Shotgun Ninja
12-06-2007, 05:30 PM
Words of Computer Wisdom:


session_start();
/* The file will not run on its own. You must write a program to MAKE it run on its own.
Doing so, and making it easy for general users to do, is one of the most difficult tasks for beginning coders,
especially due to the fact that no one will take their ideas seriously. Also, if everyone with an idea
decided to make a new file extension, we'd run out of three-letter acronyms. */
session_end();

james438
12-06-2007, 06:20 PM
a little lost here. As is often the case with me this is not a very important issue, but it might be good to know for future reference. what is infile? Is there some website I could read up more on this?

Twey, when you say pipe it into mysql it sounds like you are saying I should either enter it into the sql section of the mysqladmin page or else write a script that retrieves the data from the sql file as a variable. Am I close?

Twey
12-06-2007, 06:34 PM
No, I meant piping it, e.g.:
$ (echo 'use tablename'; cat data.sql) | mysql -u username -p

djr33
12-06-2007, 06:40 PM
You can't execute them as far as I'm aware. They are, I believe, just text... lots of sql commands. Run them as commands in mysql. You could do it through PHP, PHPMysqlAdmin, or command line, etc.

james438
12-06-2007, 06:42 PM
This is making more sense -u and -p are the password and username. not sure about the following parts though


$ (echo 'use tablename'; cat data.sql) | mysql -u username -p

It looks like it is not php, but looks close. I looked up cat on php.net and cat didn't come up.

Gotta run to class. Catch ya in a bit.

james438
12-06-2007, 06:46 PM
if it is a simple text file djr33 then that should be no problem to access and play with. I don't think I thought of that.

Twey
12-06-2007, 09:22 PM
It's bash. $ is the prompt. cat outputs the contents of a file, like DOS' type. | pipes the output of the last command (or two commands here because they're grouped with brackets) to a new command, mysql (the MySQL command-line client).

james438
12-07-2007, 04:19 AM
Thanks, that was very informative. My knowledge of web design is more limited to mostly PHP, some CSS, and a pinch of PCRE (yah, I know that is also PHP). My HTML is actually a bit rusty since my web designing practices use almost all CSS instead of HTML these days, so Bash I am not familiar with, but your explanation of how it worked was pretty clear.