How to create role with MySQL database

Nadk picture Nadk · Oct 19, 2014 · Viewed 19.5k times · Source

Is there a way to use CREATE ROLE with MySQL?

It's possible to create roles with PostgreSQL but when I try with MySQL it returns this error message:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'role famille' at line 1

Answer

Hyperdrive picture Hyperdrive · Apr 26, 2017

I note that there are people claiming that MySQL doesn't have a role implementation so I would like to add that MySQL 8.0 has a working role implementation:

Example:

CREATE ROLE r1;
GRANT r1 TO myuser@localhost;
GRANT SELECT, INSERT,UPDATE ON db1.* TO r1;

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

You can download source code and tested binaries here: https://dev.mysql.com/downloads/mysql/

At this moment in time you have to choose "development release" and MySQL server 8.0.1