How to grant all privileges to root user in MySQL 8.0
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In MySQL 8, the root account usually starts with very high privileges already. So the real question is often not “how do I make root powerful,” but “how do I inspect or adjust the account’s host access and privilege scope safely without breaking the security model.”
The Basic Grant Statement
If you truly need to grant all privileges to a root account, the classic pattern is:
This grants every privilege on every database and table to the local root account and allows it to grant privileges to others.
In MySQL 8, FLUSH PRIVILEGES is usually not necessary after normal GRANT statements because MySQL updates grant tables immediately, but many administrators still include it out of habit. The important part is the GRANT itself.
Remember That Host Matters
In MySQL, 'root'@'localhost' and 'root'@'%' are not the same account. Privileges are attached to the full user-plus-host identity.
So this account:
is different from:
and different again from:
If the login path is failing or the privileges seem inconsistent, check which host entry the client is actually matching.
Create the Account First if Needed
MySQL 8 no longer creates users implicitly through GRANT. If the account does not exist, create it first:
For an existing account, you may only need ALTER USER to reset authentication or password settings:
That distinction matters because older tutorials often assume GRANT can create the user. In MySQL 8, that is no longer the model.
Be Very Careful with Remote Root Access
You can grant full privileges to 'root'@'%', but that is usually a bad operational choice:
Technically this works if the account exists and the server allows remote access. Operationally, it expands your attack surface and violates the principle of least privilege.
A better practice is:
- keep root local when possible
- create separate admin accounts for remote administration
- restrict remote hosts explicitly instead of using
%
That gives you auditability and reduces blast radius.
Verify the Result
After changing privileges, inspect them directly:
This is the fastest way to confirm what the server thinks the account can do.
If login still fails, the problem may not be privileges at all. It may be authentication plugin configuration, host matching, bind address, or firewall settings.
Common Pitfalls
The biggest mistake is granting privileges to the wrong host-qualified account. MySQL user identities include the host, and that detail changes everything.
Another issue is assuming GRANT will create the account in MySQL 8. It will not. Use CREATE USER first when necessary.
Developers also often expose remote root access when a dedicated admin account would be safer. Full remote root privileges are rarely the best design.
Finally, do not confuse privilege problems with connection problems. A refused remote login can come from server networking or authentication settings even when the grants themselves are correct.
Summary
- The core statement is
GRANT ALL PRIVILEGES ON *.* TO 'root'@'host' WITH GRANT OPTION. - In MySQL 8, create the account explicitly if it does not already exist.
- Host-qualified accounts matter as much as usernames.
- Verify the result with
SHOW GRANTS. - Avoid broad remote root access unless there is a compelling operational reason.
Related reading
- How to grant remote access permissions to mysql server for user?
- How to group nearby latitude and longitude locations stored in SQL
- How to handle consensus in a decentralized event sourced database?
- How to handle data migrations in distributed microservice databases
- How to handle database migrations in Spring Boot with Hibernate?
- How to handle database migrations with Kubernetes and Skaffold
- How to handle many to many in DynamoDB
- How to handle SQLAlchemy Connections in ProcessPool?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.