Fix: MySQL: ERROR 1044 (42000): Access denied for user @localhost to database

Create Database mydb;

ERROR 1044 (42000): Access denied for user 'user'@'localhost' to database 'mydb'

Reason for ERROR 1044 (42000)

    If you are trying to create a database via the mysql or MariaDB prompt in Terminal and you get an error 1044 (4200), then the reason for this error is that the user that is logged-in does not have the required privileges to create a new database.

How to resolve ERROR 1044 (42000)

    If you are not the admin of the database, the best is to reach out to your database administrator (DBA)

    The DBA will need to check the following.

    1. Check what Grants the user has.
      SHOW GRANTS FOR 'user'@'localhost';
    2. If the user does not have Grants to create a database, and does need it, it can be provided using the below command,
      GRANT ALL PRIVILEGES ON db_name.* TO 'user'@'localhost';

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap