Fix for ERROR 1006 (HY000) Cant create database (errno: 2123132) in MySQL

Once MySQL is installed on macOS or Linux machines, You tried to create a database using the below command in the terminal or MySQL client for the first time

For example, create a database using the below command.

create database employeedb

It throws a below error

ERROR 1006 (HY000) Can’t create database ‘db_name’ (errno: 2123132)

Let’s see the fix and solution for this error.

Probable causes for this issue is

  • Permission to MySQL data directory
  • Disk space is full

Fix for ERROR 1006 (HY000) Can’t create a database

The following are steps to fix this issue.

First, Check the err.log file located in the MySQL installation folder. For the location, please read the next section.

For Permission issue:

  • if the error contains a permission issue to read or update a file, Then It is a permission issue with the mysqlinstallation\data directory.

Usually, when you create a schema or insert data into it, It internally stores this in the file system in the data directory of MySQL installation. The error says, there is no permission to create or update data in the file system.

The solution is to change or update the permission for the data directory.

MySQL internally uses uses mysql as user and group, so change the permissions to this user.

if you have a different user, change permissions to that user.

To do that, First First Check the location of the MySQL installation folder

In Windows,

You can easily get c:\mysql and the data location is c:\mysql\data.

In macOS or Unix machines, You can get the data directory by running the below command.

mysqladmin -uroot -p variables | grep datadir

Default directory it outputs /var/lib/mysql and output it gives as /var/lib/mysql/data

  • Next step is to change the permission for this directory using the below command
chown -R mysql:mysql /var/lib/mysql/data

if your database user is different, change mysql:mysql to a different user as newuser:newuser.

For disk full

If the issue is not permission, Next check disk filled or not using the below command

df -hk /var

If it is filled with 100%, Then see which file or folder taking more space, and remove the file to reduce the size.

Once the above steps are done, Restart the Mysql server.

/etc/init.d/mysql restart


Learned multiple ways to fix an unable to create an database error in mysql