Forums

Can't create MySQL database via CLI unless previously created on website

I've just discovered that I'm unable to create a MySQL database using the CREATE DATABASE SQL command unless the name I choose has already been used for a database created via the website interface (and since dropped).

Trying to create a new database with a new and unused name results in a 1044 access denied error:

mysql>CREATE DATABASE user$new_database;
ERROR 1044 (42000): Access denied for user 'user'@'%' to database 'user$new_database'

mysql>CREATE DATABASE user$default;
Query OK, 1 row affected (0.01 sec)

I understand that all database names have to be prefixed by a username and a $.

Is this behavior deliberate to ensure the prefix is included?

I'm actually kind of surprised that you can create the database from the command line at all! Our system should be set up so that you can only create them from the web interface. We'll have to look into that.

Is that a recent change?

I found this response of yours on a previous forum question while troubleshooting the issue earlier:

One exception to the above -- you can certainly add new databases from your code -- just issue a "CREATE DATABASE" SQL command to MySQL.

I'm condensing a setup process into a single bash file, so I thought it would be neat to include the database setup within that cascade.

Hmm, I don't know why I said that in that post -- I don't think it's ever been the case that you can create MySQL databases. Perhaps I'd not had my morning cup of tea at the time I posted it, and was thinking of Postgres or SQLite, where you can create databases, or I was thinking about tables rather than databases.