0

a file.txt have a multipe sql update.

update table1 set meta_url = replace(meta_url,'test1.jpg','test1.gif');
update table1 set meta_url = replace(meta_url,'test2.jpg','test2.gif');
update table1 set meta_url = replace(meta_url,'test3.jpg','test3.gif');
update table1 set meta_url = replace(meta_url,'test4.jpg','test4.gif');
update table1 set meta_url = replace(meta_url,'test5.jpg','test5.gif');
                          ...
update table1 set meta_url = replace(meta_url,'test100.jpg','test100.gif');

I want to create a script which allows to connect automatic, and execute all lines in file.txt at time.

the concept like that:

mysql -u root -p  ( user and password log automatic by script)

use databasename1;

update all line in file.txt

exit;

service mysql restart

1 Answer 1

1

I would recommend against storing the password in a file on the system.

mysql -u root --database=yourdatabase -p < file.sql

That will prompt you to enter the password and then run the SQL commands in the file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .