SHOW DATABASES [LIKE '数据库名'];语法说明如下:
' '
包围。mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sakila | | sys | | world | +--------------------+ 6 row in set (0.22 sec)可以发现,在上面的列表中有 6 个数据库,它们都是安装 MySQL 时系统自动创建的,其各自功能如下:
mysql> CREATE DATABASE test_db;
Query OK, 1 row affected (0.12 sec)
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sakila | | sys | | test_db | | world | +--------------------+ 7 row in set (0.22 sec)你看,刚才创建的数据库已经被显示出来了。
mysql> SHOW DATABASES LIKE 'test_db'; +--------------------+ | Database (test_db) | +--------------------+ | test_db | +--------------------+ 1 row in set (0.03 sec)2) 使用 LIKE 从句,查看名字中包含 test 的数据库:
mysql> SHOW DATABASES LIKE '%test%'; +--------------------+ | Database (%test%) | +--------------------+ | db_test | +--------------------+ | db_test_db | +--------------------+ | test_db | +--------------------+ 3 row in set (0.03 sec)3) 使用 LIKE 从句,查看名字以 db 开头的数据库:
mysql> SHOW DATABASES LIKE 'db%'; +----------------+ | Database (db%) | +----------------+ | db_test | +----------------+ | db_test_db | +----------------+ 2 row in set (0.03 sec)4) 使用 LIKE 从句,查看名字以 db 结尾的数据库:
mysql> SHOW DATABASES LIKE '%db'; +----------------+ | Database (%db) | +----------------+ | db_test_db | +----------------+ | test_db | +----------------+ 2 row in set (0.03 sec)
本文链接:http://task.lmcjl.com/news/13296.html