Raven
Raven

Reputation: 3516

MySQL alter current database

I am looking for a way to use an ALTER TABLE statement in MySQL, without having to explicitly use the currently selected (via USE) database.

Essentially, I am looking for the same thing as described here, but for MySQL instead of SQL-Server.

I already tried

ALTER DATABASE CURRENT CHARACTER SET utf8mb4;

But that returns

ERROR 3503 (42Y07): Database 'CURRENT' doesn't exist

So it seems like MySQL doesn't know the CURRENT keyword.

I also tried some variants of

ALTER DATABASE (SELECT DATABASE()) CHARACTER SET utf8mb4;

but I can't seem to get it to work with that either (it always complains about invalid syntax).
Note that I know, that the plain SELECT DATABASE() gives me the sought-after name of the current database - I just can't get it to do that within the ALTER DATABASE statement.

How would I achieve my goal within MySQL?

Upvotes: 1

Views: 287

Answers (1)

Raven
Raven

Reputation: 3516

Oops, it seems I was trying too hard. Turns out that the database name is optional in ALTER DATABASE. So a plain

ALTER DATABASE CHARACTER SET utf8mb4

is all that is needed.

Upvotes: 3

Related Questions