How to check the existence of a database?

  • 0
    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 stupid
    Java Lydia Cisneros, Jun 1, 2020

  • 1 Answers
  • 0
    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 5.7 / en / create-database.html

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!