I am attempting to write a shell script that executes a query on a mysql database. It seems to run fine in the mysql panel, but not in the script.

The code is:

mysql -u username -ppassword -e 'delete from table where forumid = 25 and replace (title, ' ', '') like '%word%'';

When I run this script I get this error: Access denied for username@localhost to database ' , ) like %word%'

Any idea what is causing this error?



The problem is that you're not providing a database name! Try this: mysql -uusername -ppassword database_name ... Hope that helps!

EDIT: And to clarify that error you're getting, since you're surrounding your "-e" with single quotes (' '), and you have single quotes inside the string, it ends your query at the next occurrence of single quotes:

'delete from table where forumid = 25 and replace (title, '

and thinks the next part:

' , ) like %word%'

is supposed to be the database name! Try using regular quotes in one of those instances. Backslashes might be used to escape the occurrence inside the query... not sure though without testing it... :)



Thanks for the help. I simply forgot to include the use database statement in my example, but I wouldn't have thought of the ' causing the problem.

Thanks again