获取到初识密码
pwd=$(grep 'temporary password' /var/log/mysqld.log |awk '{print $NF}')
查询库名是否存在 服务器中
mysql> select SCHEMA_NAME from information_schema.SCHEMATA where SCHEMA_NAME="db1d"\G
Empty set (0.00 sec)
mysql> select SCHEMA_NAME from information_schema.SCHEMATA where SCHEMA_NAME="db1"\G
*************************** 1. row ***************************
SCHEMA_NAME: db1
1 row in set (0.00 sec)
mysql>
mysql> select * from information_schema.SCHEMATA where SCHEMA_NAME="db1"\G
*************************** 1. row ***************************
CATALOG_NAME: def
SCHEMA_NAME: db1
DEFAULT_CHARACTER_SET_NAME: utf8mb4
DEFAULT_COLLATION_NAME: utf8mb4_0900_ai_ci
SQL_PATH: NULL
DEFAULT_ENCRYPTION: NO
1 row in set (0.00 sec)
查询某个表是否存在指定的库中
mysql> select * from information_schema.TABLES where TABLE_SCHEMA='sharkdb' and TABLE_NAME="t1"\G
*************************** 1. row ***************************
TABLE_CATALOG: def
TABLE_SCHEMA: sharkdb
TABLE_NAME: t1
TABLE_TYPE: BASE TABLE
ENGINE: InnoDB
VERSION: 10
ROW_FORMAT: Dynamic
TABLE_ROWS: 0
AVG_ROW_LENGTH: 0
DATA_LENGTH: 16384
MAX_DATA_LENGTH: 0
INDEX_LENGTH: 0
DATA_FREE: 0
AUTO_INCREMENT: NULL
CREATE_TIME: 2020-09-22 20:16:42
UPDATE_TIME: NULL
CHECK_TIME: NULL
TABLE_COLLATION: utf8mb4_0900_ai_ci
CHECKSUM: NULL
CREATE_OPTIONS:
TABLE_COMMENT:
1 row in set (0.00 sec)
mysql>