Forum Moderators: open

Message Too Old, No Replies

Run batch sql file against database

         

3321thec

2:16 am on Nov 28, 2007 (gmt 0)

10+ Year Member



Is it posssible to run a batch sql file against a MySql database?

What would even better would be to create a stored procedure so I can pass a parameter to the batch.

Are either one of these possible on MySql v4.1.22 and php?

Any help is appreciated!

~3321thec

vincevincevince

2:24 am on Nov 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can pipe any sql directly to mysql at the shell prompt. Changing parameters can be achieved using sed or any other method you choose to use.

Basic pipe:

cat batch.sql ¦ mysql -uusername -ppassword databasename

Basic pipe with sed substitution of MYUSERNAME -> john:

cat batch.sql ¦ sed 's/MYUSERNAME/John/g' ¦ mysql -uusername -ppassword databasename

3321thec

2:26 pm on Nov 28, 2007 (gmt 0)

10+ Year Member



First off, thanks for replying.
But can this be done by a php script?

My basic dillema is that i need to duplicate 62 tables exactley as i have them in the batch file(which is a dump of the database), but i need to append a username to the begging of each of the new tables. But this must all be done from a form with php.

Any help appreciated!

~3321thec

vincevincevince

3:04 pm on Nov 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you can do it with PHP. You'll need to load up the file, statement at a time, and then run a mysql_query() with each. str_replace() or similar will allow you to modify / substitute.