Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Currently I'm using mysql -u root -p and fill the password

and then in MySQL command line, I'm using:

use dbname;
update node_revisions set body = replace(body,'textone','texttwo');

How can I doing this in terminal without entering MySQL command line?

share|improve this question

closed as not a real question by womble, Michael Hampton, mulaz, Scott Pack, HopelessN00b Sep 27 '12 at 22:42

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 4 down vote accepted

Easy peasy:

$ mysql -u root -p dbname -e "update node_revisions set body = replace(body,'textone','texttwo')"
share|improve this answer
You can also do mysql -u root -p dbname < file.sql if you have a bunch of commands you want to run – Zypher Aug 26 '11 at 1:56

You can make it so that it won't ask you for the password by creating a file called .my.cnf in your home directory, and adding:


Then you can use the -e option to mysql to specify the SQL to execute, for example:

mysql -u username -e "update node_revisions set body = replace(body,'textone','texttwo');"

This will give you the ability to list the SQL to execute right at the command line and will not ask you for the password for every statement.

share|improve this answer
Yep, this is surely an option. Some would argue, though, that, like when using sudo, requiring you to manually enter your password acts as a safety valve of sorts, giving you another couple of seconds to verify mentally if this is the correct command you want to run. – EEAA Aug 27 '11 at 0:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.