MySQL增刪改查

2021-09-30 10:26:35 字數 3697 閱讀 8491

建立資料庫和建立表請看

選擇zhaochao資料庫,並檢視user表中字段如下:

insert into user (id,username,userpasswd) values (3,'趙超','zhaochao');

insert into user values (4,'趙雲','zhaoyun');

將自身插入自身

|    3 | 趙超     | zhaochao   |

|    4 | 趙雲     | zhaoyun    |

+------+----------+------------+

4 rows in set (0.00 sec)

mysql> delete from user where id=4;

query ok, 1 row affected (0.03 sec)

mysql> select * from user;

+------+----------+------------+

| id   | username | userpasswd |

+------+----------+------------+

|    1 | admin    | admin      |

|    2 | zhaochao | zhaochao   |

|    3 | 趙超     | zhaochao   |

+------+----------+------------+

3 rows in set (0.00 sec)

update user set username='root' where id=1;
mysql> select * from user;

+------+----------+------------+

| id   | username | userpasswd |

+------+----------+------------+

|    1 | admin    | admin      |

|    2 | zhaochao | zhaochao   |

|    3 | 趙超     | zhaochao   |

+------+----------+------------+

3 rows in set (0.00 sec)

mysql> update user set username='root' where id=1;

query ok, 1 row affected (0.03 sec)

rows matched: 1  changed: 1  warnings: 0

mysql> select * from user;

+------+----------+------------+

| id   | username | userpasswd |

+------+----------+------------+

|    1 | root     | admin      |

|    2 | zhaochao | zhaochao   |

|    3 | 趙超     | zhaochao   |

+------+----------+------------+

3 rows in set (0.00 sec)

select id,username,userpasswd from user;
mysql> select id,username,userpasswd from user;

+------+----------+------------+

| id   | username | userpasswd |

+------+----------+------------+

|    1 | root     | admin      |

|    2 | zhaochao | zhaochao   |

|    3 | 趙超     | zhaochao   |

+------+----------+------------+

3 rows in set (0.00 sec)

select id '使用者編號',username '使用者名稱',userpasswd '密碼' from user a where a.id=1 ;
mysql> select id '使用者編號',username '使用者名稱',userpasswd '密碼' from user a where a.id=1 ;

+----------+--------+-------+

| 使用者編號 | 使用者名稱 | 密碼  |

+----------+--------+-------+

|        1 | root   | admin |

+----------+--------+-------+

1 row in set (0.00 sec)

select id,username,userpasswd from user limit 1,2;
mysql> select id,username,userpasswd from user limit 1,2;

+------+----------+------------+

| id   | username | userpasswd |

+------+----------+------------+

|    2 | zhaochao | zhaochao   |

|    3 | 趙超     | zhaochao   |

+------+----------+------------+

2 rows in set (0.00 sec)

mysql增刪改查效果 mysql增刪改查

檢視所有資料庫 mysql show databases 建立乙個庫ghd並指定字符集為utp8 mysql create database ghd charset utf8 檢視mysql支援的字符集 mysql show char set 建立乙個表,並設定id為主鍵 create table ...

mysql增刪改查擴充套件 MySQL增刪改查

1 插入 insert 1 insert into 表名 values 值1 值2 例子 insert into t1 values zengsf 23 fengshao 22 2 insert into 表名 欄位1,values 值1 例子 insert into t1 name values ...

mysql建刪改查 MySQL增刪改查

登入mysql mysql u root p 密碼 建立使用者 mysql insert into mysql.user host,user,password values localhost test password 1234 這樣就建立了乙個名為 test 密碼為 1234 的使用者。注意 此...