I would like to update a MySQL database table column with x. How would I be able to do this without having to do so interactively from the mysql> prompt? I want to do this with one simple command.

  • If you don't login to the database you can't access it. If you can't access it you can't make the change. – roaima May 28 '15 at 14:31
  • I meant do it with one line command. Login with user/pass and command also – Teddy291 May 28 '15 at 14:40
  • Please update your question to make that clear. – roaima May 28 '15 at 14:45

You could execute the mysql command with -e option, like this:

$ mysql -u user -pPASSWORD -e 'UPDATE QUERY;'

From man mysql

--execute=statement, -e statement
Execute the statement and quit. The default output format is like that
produced with --batch. See Section 4.2.4, “Using Options on the
Command Line”, for some examples. With this option, mysql does not use
the history file.

Give a try!

NOTE: Is not advisable to put the password in line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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