Managing Users & Access Rights in MySQL
MySQL·3 min read·Jan 1, 2025
In information security, the principle of least privilege recommends that a user, system, or application should only have the minimum level of access needed to perform their tasks.
In MySQL, the root account should be reserved for administrative tasks only, and everyday operations should be carried out using accounts with limited, role-specific privileges.
Generally, using an account with full administrative privileges is not recommended as it often leads to severe breaches and damages on both the database structure and its data.
In short, creating users with limited privileges helps to enhance security, reduce the risk of errors, ensure compliance, and maintain better control over your MySQL environment.
Managing user accounts
To manage user accounts and privileges, you will need to initially connect to the database instance using an account with full administrative privileges, such as the root account:
$ mysql -u root -pNote: The password of the
rootaccount is by default set toroot.
Creating a new user
To create a new user account, you can use the CREATE USER keywords:
CREATE USER 'username'@'host' IDENTIFIED BY 'password';Where:
-
'username'is the name of the new user account.
Unlock the Build RESTful APIs in Node.js module
Learn how to build real database-backed and framework-powered RESTful APIs with MySQL, Sequelize, and Express.
You get immediate access to:
- 37 focused lessons across MySQL, Sequelize, backend, and Express
- 4 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle