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';

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!