0

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?

Thanks

2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by macuhail
0

Hi!

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

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... :)

-G

0

Gromit,

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.