Adding users in MySQL

It seems I end up doing this frequently, but never frequent enough so that I remember the syntax from last time. So here it is, instead of having to resort to the MySQL documentation page (which is rather good actually, but a bit fragmented):

GRANT [privileges] ON [database].[table] TO 'user'@'host' IDENTIFIED BY 'password';

[privileges] can be the usual commands, SELECT, INSERT, UPDATE, DELETE, etc. or ALL which gives all privileges but GRANT.
[database] is the name of the database in which the user will have the privileges
[table] can be any existing table in the specified database, or *
‘password’ is the password of the user.

Example:

GRANT ALL ON dbTest.* TO 'kalle'@'localhost' IDENTIFIED BY 'anka';

Leave a Reply