MySql - How to Create a New User

  • Time to read less than 1 minute
MySql - How to Create a New User

Make a new user within the MySQL shell:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

replace newuser and password with the new username and password but leave 'localhost' not the servers IP as this is the host for the mysql account.

Next step is to set some permissions

GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'localhost';

replace the * with a spercific table if you would like the user to only have access to a subset of the tables, if not leave as an * to grant them access to all tables in this database.

Lastly reload all the permissions.

FLUSH PRIVILEGES;

That's it, you new user can now access the relevant databases