Check if mysql database exists, perform action based on result

前端 未结 20 2031
傲寒
傲寒 2021-02-01 16:02

Is it possible from within a bash script to check if a mysql database exists. Depending on the result then perform another action or terminate the script?

20条回答
  •  再見小時候
    2021-02-01 16:30

    Use the -e option to the mysql command. It will let you execute any query (assuming the right credentials).

    This may be an example:

    if mysql "DATABASE_NAME" -e exit > /dev/null 2>&1; then
        echo "Exists"
    else
        echo "Not exists"
    fi
    

提交回复
热议问题