Syntax error MySQL query to update all entries with md5 version of name?

MySQL query to update all entries with md5 version of name?



For this, you can use MD5(). Let us first create a table −

mysql> create table DemoTable1887
   (
   Password text,
   HashPassword text
   );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1887(Password) values('John@9089');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1887(Password) values('90987_Carol');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1887(Password) values('656464_David_4343');
Query OK, 1 row affected (0.00 sec)

Display some records in the table using insert command −

mysql> select * from  DemoTable1887;

This will produce the following output −

+-------------------+--------------+
| Password          | HashPassword |
+-------------------+--------------+
| John@9089         |          NULL|
| 90987_Carol       |          NULL|
| 656464_David_4343 |          NULL|
+-------------------+--------------+
3 rows in set (0.00 sec)

Here is the query to update all entries with md5 version of name:

mysql> update DemoTable1887 set HashPassword=md5(Password);
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3 Warnings: 0

Let us check the table records once again:

mysql> select * from  DemoTable1887;

This will produce the following output −

+-------------------+----------------------------------+
| Password          | HashPassword                     |
+-------------------+----------------------------------+
| John@9089         | 7f92a7e09ab1a0cd3f36ec164f035c9a |
| 90987_Carol       | 1578fa8c47f0e53a898c8ada5c0111b4 |
| 656464_David_4343 | e5ec2bd2cb55b2252be7ca9eb546659e |
+-------------------+----------------------------------+
3 rows in set (0.00 sec)
Updated on: 2019-12-27T06:43:27+05:30

875 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements