- 查看表内行数 ```shell mysql> select count() from mysql.user; +—————+ | count() | +—————+ | 9 | +—————+ 1 row in set (0.00 sec)
mysql>
1. 查看表内行数
```shell
mysql> select * from mysql.db;
+---------------+---------+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
| Host | Db | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Execute_priv | Event_priv | Trigger_priv |
+---------------+---------+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
| % | test | | Y | Y | Y | Y | Y | Y | N | Y | Y | Y | Y | Y | Y | Y | Y | N | N | Y | Y |
| % | test\_% | | Y | Y | Y | Y | Y | Y | N | Y | Y | Y | Y | Y | Y | Y | Y | N | N | Y | Y |
| 192.168.133.1 | db1 | user2 | Y | Y | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N |
| % | db1 | user3 | Y | Y | Y | Y | Y | Y | N | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
+---------------+---------+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
4 rows in set (0.00 sec)
- 查看db表内含有db字段的内容
```shell mysql> select db from mysql.db; +————-+ | db | +————-+ | db1 | | test | | test_% | | db1 | +————-+ 4 rows in set (0.00 sec)
3. 查看db表内含有db字段的内容
```shell
mysql> select db,user from mysql.db;
+---------+-------+
| db | user |
+---------+-------+
| db1 | user3 |
| test | |
| test\_% | |
| db1 | user2 |
+---------+-------+
4 rows in set (0.00 sec)
mysql>
- 查询host为192.168的内容
```shell
mysql> select from mysql.db where host like ‘192.168.%’\G;
* 1. row *
References_priv: NHost: 192.168.133.1
Db: db1
User: user2
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: N
Create_priv: N
Drop_priv: N
Grant_priv: N
Create_tmp_table_priv: N Lock_tables_priv: N Create_view_priv: NIndex_priv: N
Alter_priv: N
Create_routine_priv: N Alter_routine_priv: NShow_view_priv: N
1 row in set (0.00 sec)Execute_priv: N
Event_priv: N
Trigger_priv: N
ERROR: No query specified
6. 向db1.t1中插入内容
```shell
mysql> insert into db1.t1 values(1,'abc');
Query OK, 1 row affected (0.01 sec)
mysql> select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | abc |
+------+------+
1 row in set (0.00 sec)
- 把id=1的字段内容更新成aaa ```shell mysql> update db1.t1 set name=’aaa’ where id = 1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from db1.t1; +———+———+ | id | name | +———+———+ | 1 | aaa | +———+———+ 1 row in set (0.00 sec)
8. 清空db1.t1表内的内容
```shell
mysql> truncate table db1.t1;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from db1.t1;
Empty set (0.00 sec)
- 删除db1.t1数据库 ```shell mysql> mysql> drop database db1; Query OK, 1 row affected (0.00 sec)
mysql> mysql> show databases; +——————————+ | Database | +——————————+ | information_schema | | mysql | | performance_schema | | test | | ytl | +——————————+ 5 rows in set (0.00 sec)
mysql>
```