Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

add comment

2 Answers 2

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
1  
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
add comment

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:

[client]
host=127.0.0.1
password=<YOUR_PASSWORD>

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
add comment

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