MySQL 8.0+ does not allow creating users implicitly through GRANT statements. You must create the user first with CREATE USER, then grant privileges separately.
In MySQL versions prior to 8.0, you could create a new user and assign privileges in a single GRANT statement. Starting with MySQL 8.0, this behavior was removed for security and clarity reasons. When you attempt the old syntax (combining user creation with GRANT), MySQL returns ERROR 1410 because it no longer supports implicit user creation through GRANT statements. This enforces a clearer separation of concerns: user creation is handled by CREATE USER, while privilege assignment is handled by GRANT. Additionally, this error can occur when a user without the GRANT OPTION privilege attempts to assign privileges to another user, preventing privilege escalation attacks.
Replace single-statement syntax with two separate commands. Instead of:
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost' IDENTIFIED BY 'password';Use the MySQL 8.0+ syntax:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';The CREATE USER statement creates the account first, then GRANT assigns privileges to the existing user.
After running GRANT statements, execute FLUSH PRIVILEGES to ensure the changes take effect immediately:
FLUSH PRIVILEGES;Note: In MySQL 8.0+, FLUSH PRIVILEGES is often optional (changes apply automatically), but it's a safe practice to include.
Confirm the user exists and has the correct privileges:
SELECT user, host FROM mysql.user WHERE user='username';
SHOW GRANTS FOR 'username'@'localhost';This ensures the account was created and privileges are properly assigned.
If you have SQL initialization scripts from MySQL 5.7, update them to use separate CREATE USER and GRANT statements. Search for patterns like:
GRANT ... IDENTIFIED BYAnd split them into two statements. Many ORMs and migration tools (Prisma, TypeORM, Sequelize) have features to handle this automatically—check your tool's documentation for MySQL 8.0 compatibility modes.
MySQL 8.0 introduced stricter user management to improve security. The separate CREATE USER and GRANT statements allow for better audit trails and prevent accidental privilege escalation.
If you're migrating from MySQL 5.7 to 8.0, update all database initialization scripts. Some tools provide backward compatibility modes, but it's recommended to adopt the 8.0+ approach for new projects.
For applications using ORMs like Sequelize, TypeORM, or Prisma, check that your version supports MySQL 8.0+ properly. Many older ORM versions still generate legacy syntax and need updates.
ERROR 1064: You have an error in your SQL syntax
How to fix "ERROR 1064: You have an error in your SQL syntax" in MySQL
ERROR 1054: Unknown column in field list
Unknown column in field list
ER_WINDOW_RANGE_FRAME_NUMERIC_TYPE (3589): RANGE frame requires numeric ORDER BY expression
RANGE frame requires numeric ORDER BY expression in MySQL window functions
CR_ALREADY_CONNECTED (2058): Handle already connected
How to fix "CR_ALREADY_CONNECTED (2058): Handle already connected" in MySQL
ER_WINDOW_DUPLICATE_NAME (3591): Duplicate window name
How to fix ER_WINDOW_DUPLICATE_NAME (3591) in MySQL window functions