How to update data in MySQL table

Here's how to update existing data into MySQL database table.

update table set column='new_value' where where_condition;

The update statement updates columns of existing rows in the table with new values.
The table is the table name.
The set clause indicates which column to modify and the values they should be given.
The where clause specifies the conditions that identify which rows to update. Its very useful if you want to update selected rows in a table.
Example:
You want to change the password of "user" from "password" to "123".

  1. +----+----------+--------------------+----+----------+
  2. | id | username | attribute          | op | value    |
  3. +----+----------+--------------------+----+----------+
  4. |  1 | user     | Cleartext-Password | := | password |
  5. +----+----------+--------------------+----+----------+

To do it, type this command:

update radcheck set value='123' where id=1;

Check your

select * from radcheck;

Check the changes

  1. +----+----------+--------------------+----+-------+
  2. | id | username | attribute          | op | value |
  3. +----+----------+--------------------+----+-------+
  4. |  1 | user     | Cleartext-Password | := | 123   |
  5. +----+----------+--------------------+----+-------+
  6. 1 row in set (0.00 sec)

No votes yet

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may quote other posts using [quote] tags.

More information about formatting options