系列文章目录
数据库的查询2一、查看数据库
[root@server15 mnt]# mysql -uroot -p
MariaDB [(none)]> SHOW DATABASES; 查看有什么库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
二、进入库并且查看数据库中的表
MariaDB [(none)]> USE mysql; 进入这个库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> SHOW TABLES; 查看表
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
三、查看数据库里所有表的名字
MariaDB [mysql]> SHOW TABLES FROM mysql;
查看mysql库里面所有表的名字
四、查看数据库里所有表的名字
MariaDB [mysql]> SELECT * FROM user;
查看user表里面的所有内容
4.1表里面的字段
表里面的字段
4.2查看表里面的字段
MariaDB [mysql]> SELECT Host,User,Password FROM user;
+-----------+------+-------------------------------------------+
| Host | User | Password |
+-----------+------+-------------------------------------------+
| localhost | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| 127.0.0.1 | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| ::1 | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
+-----------+------+-------------------------------------------+
3 rows in set (0.00 sec)
查看表里面的字段可以接条件
MariaDB [mysql]> SELECT Host,User,Password FROM user WHERE User='root' and Host='localhost';
+-----------+------+-------------------------------------------+
| Host | User | Password |
+-----------+------+-------------------------------------------+
| localhost | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)
.表示分级
MariaDB [(none)]> SELECT Host,User,Password FROM mysql.user WHERE User='root' and Host='localhost';
+-----------+------+-------------------------------------------+
| Host | User | Password |
+-----------+------+-------------------------------------------+
| localhost | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)
END