mysqldatabase-permissions

MySQL : How to grant "ALTER DATABASES" to a USER


A user needs to do :

ALTER DATABASE `dbname` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

...but even with a :

GRANT ALL PRIVILEGES ON dbname.* TO 'user_name'@'localhost' IDENTIFIED BY '***';

...the user is not allowed to do that.

I found some websites where it is advised to do

GRANT USAGE ON SCHEMA dbname...

...but even in MySQL 8 (sorry we have Mysql 5 on this server) this does not seems to exist :

https://dev.mysql.com/doc/refman/8.0/en/grant.html

Sorry if this question is completely out of score, stupid, or whatsoever, but even with "good" MySQL knowledge I don't understand what I am doing wrong or what I should do.

Thanks a lot in advance for any help !

Denis


Solution

  • This answer is in the documentation. https://dev.mysql.com/doc/refman/8.0/en/alter-database.html says:

    This statement requires the ALTER privilege on the database.

    The GRANT USAGE only allows that user to connect to the server. It doesn't give privileges to do any SQL statement. In fact, it does not make sense to GRANT USAGE on a specific database. If you try, the user ends up with only USAGE privilege at the server level:

    mysql> grant usage on `dbname`.* to 'testuser'@'%';
    Query OK, 0 rows affected, 1 warning (0.03 sec)
    
    mysql> show grants for 'testuser'@'%';
    +--------------------------------------+
    | Grants for testuser@%                |
    +--------------------------------------+
    | GRANT USAGE ON *.* TO 'testuser'@'%' |
    +--------------------------------------+