1. User creation
mysql> CREATE USER 'myuser' IDENTIFIED BY 'mypassword';
2. Grant permissions to access and use the MySQL server
Only allow access from localhost (this is the most secure and common configuration you will use for a web application):
mysql> GRANT USAGE ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword';
3. Grant all privileges to a user on a specific database
mysql> GRANT ALL privileges ON `mydb`.* TO 'myuser'@localhost;
As in the previous command, if you want the user to work with the database from any location you will have to replace localhost with ‘%’.
4. Apply changes made
To be effective the new assigned permissions you must finish with the following command:
mysql> FLUSH PRIVILEGES;
5. Verify your new user has the right permissions
mysql> SHOW GRANTS FOR 'myuser'@localhost;
mysql> CREATE USER 'myuser' IDENTIFIED BY 'mypassword';
2. Grant permissions to access and use the MySQL server
Only allow access from localhost (this is the most secure and common configuration you will use for a web application):
mysql> GRANT USAGE ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword';
3. Grant all privileges to a user on a specific database
mysql> GRANT ALL privileges ON `mydb`.* TO 'myuser'@localhost;
As in the previous command, if you want the user to work with the database from any location you will have to replace localhost with ‘%’.
4. Apply changes made
To be effective the new assigned permissions you must finish with the following command:
mysql> FLUSH PRIVILEGES;
5. Verify your new user has the right permissions
mysql> SHOW GRANTS FOR 'myuser'@localhost;