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: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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