差异-in“创建数据库”和“如果不存在则创建数据库”

What is the actual difference between "CREATE DATABASE database_name" and "CREATE DATABASE IF NOT EXISTS database_name"?

CREATE DATABASE IF NOT EXISTS database_name will execute the CREATE DATABASE database_name only if the database_name does not already exist.

If the database_name does not exit, both queries will do the same job, that is they create the database_name.

If the database_name exits, CREATE DATABASE database_name will return an error similar to "the database 'database_name' already exists", while CREATE DATABASE IF NOT EXISTS database_name will not return an error (it simply does nothing).

When you write a script (let's say you create the database, then create tables, then insert some data), you don't want the execution to stop just because the database exits, so you use the second query.

only one thing:

An error occurs if the database exists and you did not specify IF NOT EXISTS.

https://dev.mysql.com/doc/refman/5.5/en/create-database.html

so basically for : error management.