Skip to content

Create a new MySQL user and grant permissions

If you have a server with multiple databases, you usually don’t want to access them with an account with privileges to them all from your application(s), in case of a successful hack. It’s better instead to create a new user and grant this user only privileges on the wished database. Here’s how to do that:

CREATE USER '<username>'@'localhost' IDENTIFIED BY '<password>';
GRANT ALL PRIVILEGES ON *.* TO '<username>'@'localhost'; -- Grants all rights to all databases on the server. NOT RECOMMENDED FOR SECURITY REASONS
GRANT ALL PRIVILEGES ON <database>.* TO '<username>'@'localhost'; -- Grants all rights to the database <database>.
FLUSH PRIVILEGES;

(source)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.