View Full Version : mySQL Source command
horizon 05-25-2008, 09:33 PM Hi,
I have created a database name called: toto and I have also created an SQL file which has some SQL queries inside (obviously). How can this be achieved if I use the SOURCE toto.txt in order to execute the SQL file ?
azizny 05-26-2008, 12:07 AM mysql_query($contentoffile);
Peace,
horizon 05-26-2008, 07:10 AM I should of add that this request doesn't have anything to do with PHP this time ... it's from the console in linux ... any ideas ?
foutrelis 05-26-2008, 09:03 AM The source command is run from within the mysql client. Take a look at the mysql manual (http://dev.mysql.com/doc/refman/5.0/en/batch-commands.html) and don't hesitate to ask if you have further questions. :)
Burhan 05-26-2008, 11:25 AM $ mysql
mysql> use toto;
Database changed
mysql> source toto.txt
OR,
$ mysql -u myUser -p toto < toto.txt
Note that $ is your shell prompt, you don't actually type that.
horizon 05-26-2008, 11:40 AM Hi, thanks for your response. I tried that already and the command does execute. Althought, the SQL file isn't considered in the execution while applying the TXT file. Is there something I'm missing ?
Burhan 05-26-2008, 11:41 AM The file needs to be in the same directory from which you start the mysql command.
horizon 05-26-2008, 12:59 PM It is, indeed. Althought it does not seem to respond with the SQL file. As I said, the SOURCE command does seem to work but does not do anything while responding. Other ideas ?
ThatScriptGuy 05-26-2008, 01:52 PM If the file contains SQL queries, then
mysql -u myUser -p toto < toto.txt
should import it into the database.
horizon 05-26-2008, 02:35 PM No, ok. Let me re-explain the problem. I have an SQL file and a TXT file . The SQL file contains the SQL queries. The TXT file is what is used with the SOURCE command from the console. Now, how can I execute the TXT file in order to see the SQL for execution with the SOURCE command ?
sasha 05-26-2008, 04:03 PM No, ok. Let me re-explain the problem. I have an SQL file and a TXT file . The SQL file contains the SQL queries. The TXT file is what is used with the SOURCE command from the console. Now, how can I execute the TXT file in order to see the SQL for execution with the SOURCE command ?
I keep reading that and I do not get it.
I understand that you have 2 files, one file with SQL queries (which you refer to as SQL file ) and one more file (again with SQL queries) (which you refer to as TXT file). You just want to run queries from both of those files?
horizon 05-26-2008, 04:13 PM 1 = toto.txt
2 = toto.sql
how can see if toto.txt sees toto.sql while SOURCING ?
sasha 05-26-2008, 05:24 PM 1 = toto.txt
2 = toto.sql
how can see if toto.txt sees toto.sql while SOURCING ?
The files cannot see each other. MySQL SOURCE command simply runs the queries listed in the file you specify. So if you type in "SOURCE toto.txt" while in mysql shell, MySQL will execute statements in the file called toto.txt (you can provide absolute or relative path to file). If you type "SOURCE toto.sql (or "\. toto.sql" which is the same thing), MySQL will run SQL statements you have in file toto.sql. There is nothing smart there.
horizon 05-26-2008, 09:38 PM The files cannot see each other. MySQL SOURCE command simply runs the queries listed in the file you specify.
Exactly the reply I was expecting. Very well, thanks for your response. :)
|