我将仇恨写在冰上,然后期待太阳的升起。——加西亚马尔克斯

打开mysql官方文档:Information Functions

可以看到mysql查询库表信息的函数

Name Description
BENCHMARK() Repeatedly execute an expression
CHARSET() Return the character set of the argument
COERCIBILITY() Return the collation coercibility value of the string argument
COLLATION() Return the collation of the string argument
CONNECTION_ID() Return the connection ID (thread ID) for the connection
CURRENT_ROLE() Return the current active roles
CURRENT_USER(), CURRENT_USER The authenticated user name and host name
DATABASE() Return the default (current) database name
FOUND_ROWS() For a SELECT with a LIMIT clause, the number of rows that would be returned were there no LIMIT clause
ICU_VERSION() ICU library version
LAST_INSERT_ID() Value of the AUTOINCREMENT column for the last INSERT
ROLES_GRAPHML() Return a GraphML document representing memory role subgraphs
ROW_COUNT() The number of rows updated
SCHEMA() Synonym for DATABASE()
SESSION_USER() Synonym for USER()
SYSTEM_USER() Synonym for USER()
USER() The user name and host name provided by the client
VERSION() Return a string that indicates the MySQL server version

除了USERVERSIONLAST_INSERT_ID以外等常用函数还有DATABASE

这个可以用于获取当前USE的数据库

例如获取当前数据库中的所有表,sql如下:

1
select * from information_schema.tables where table_schema = (select database());

这些函数常用的场景如代码生成器和数据库备份维护应用等