跳到主要内容

十三、MySQL 列出数据表

如果要查看当前选择的数据库有哪些表,可以使用 SHOW TABLES; 命令

在 mysql>` 终端中查看数据库列表

打开一个终端(命令行),输入 mysql -u root -p 进入 mysql> 命令行

然后输入 USE souyunku; 选择 souyunku 数据库

最后输入 SHOW TABLES; 命令就可以查看当前选择的数据库有哪些表

$ mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 117
Server version: 10.2.13-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use souyunku;
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 [souyunku]> SHOW TABLES;
+----------------+
| Tables_in_souyunku |
+----------------+
| tbl_lang |
| tbl_language |
+----------------+
2 rows in set (0.00 sec)

> 你创建的数据库里可能没有这些表,因为这篇教程是后面添加的

PHP 列出当前数据库有哪些表

PHP可以使用 PDO::query() 函数可以用来列出当前选择的数据库有哪些表

PDO::query() 函数原型