mysql> select * from users;
+-------+-------------+------------------------------------------------------------------+---------------+--------+
| id | username | password | email | status |
+-------+-------------+------------------------------------------------------------------+---------------+--------+
| 10005 | ??134 | ccb797aae770710012a7b0e5834e7ee5c1994f80a31bc86332b96e1c90015cea | 0 | 0 |
| 10006 | ???? | 31ed43c7ba20fa7b2600b200b064de3c7cdbafe0c32019101daf93203c8ac27b | NULL | 0 |
| 10007 | ceshiyonghu | 111 | 110000@qq.com | 1 |
| 10008 | liu | | NULL | 0 |
+-------+-------------+------------------------------------------------------------------+---------------+--------+
查询某个字段
mysql> select id, username from users;
+-------+-------------+
| id | username |
+-------+-------------+
| 10005 | ??134 |
| 10006 | ???? |
| 10007 | ceshiyonghu |
| 10008 | liu |
+-------+-------------+
4 rows in set (0.00 sec)
5. 更新某个字段
mysql> update users set username = 'liu2' where id = 10008;
Query OK, 1 row affected (0.00 sec)
where语句用来定位某几行
mysql> select * from users;
+-------+-------------+------------------------------------------------------------------+---------------+--------+
| id | username | password | email | status |
+-------+-------------+------------------------------------------------------------------+---------------+--------+
| 10005 | ??134 | ccb797aae770710012a7b0e5834e7ee5c1994f80a31bc86332b96e1c90015cea | 0 | 0 |
| 10006 | ???? | 31ed43c7ba20fa7b2600b200b064de3c7cdbafe0c32019101daf93203c8ac27b | NULL | 0 |
| 10007 | ceshiyonghu | 111 | 110000@qq.com | 1 |
| 10008 | liu2 | | NULL | 0 |
+-------+-------------+------------------------------------------------------------------
更新多个字段
mysql> update users set username = 'liu2' , password = '222' where id = 10008;
Query OK, 1 row affected (0.00 sec)
mysql> select * from users;
+-------+-------------+------------------------------------------------------------------+---------------+--------+
| id | username | password | email | status |
+-------+-------------+------------------------------------------------------------------+---------------+--------+
| 10005 | ??134 | ccb797aae770710012a7b0e5834e7ee5c1994f80a31bc86332b96e1c90015cea | 0 | 0 |
| 10006 | ???? | 31ed43c7ba20fa7b2600b200b064de3c7cdbafe0c32019101daf93203c8ac27b | NULL | 0 |
| 10007 | ceshiyonghu | 111 | 110000@qq.com | 1 |
| 10008 | liu2 | 222 | NULL | 0 |
+-------+-------------+------------------------------------------------------------------+---------------+--------+
6. 删除记录:
mysql> delete from users where id = 10008;
Query OK, 1 row affected (0.00 sec)
mysql> select * from users;
+-------+-------------+------------------------------------------------------------------+---------------+--------+
| id | username | password | email | status |
+-------+-------------+------------------------------------------------------------------+---------------+--------+
| 10005 | ??134 | ccb797aae770710012a7b0e5834e7ee5c1994f80a31bc86332b96e1c90015cea | 0 | 0 |
| 10006 | ???? | 31ed43c7ba20fa7b2600b200b064de3c7cdbafe0c32019101daf93203c8ac27b | NULL | 0 |
| 10007 | ceshiyonghu | 111 | 110000@qq.com | 1 |
+-------+-------------+------------------------------------------------------------------+---------------+--------+