How to check the existence of a database?
The question is how to check if the required database already exists on the device? It is the database, not the tables.
As a crooked option, always create a database at startup, if it exists, then catch an exception, but this is somehow stupidJava Lydia Cisneros, Jun 1, 2020
Connect and command
show databases like 'db_name'
If there is a line in the response, then there is a database. Empty means there is none.
Plus, create database has idempotent behavior.
CREATE DATABASE IF NOT EXISTS db_name
dev.mysql.com/doc/refman/ 5.7 / en / create-database.htmlAnonymous
To place the code, please use CodePen or similar tool. Thanks you!