问题
I am facing problem creating the database and it results in following error.
mysql> show grants for 'admin'@'%';
+---------------------------------------------------------------------------------------------------------------------------------+
| Grants for admin@% |
+---------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY PASSWORD '*4ACFE3202A5FF5CF467898FC58AAB1D615029441' WITH GRANT OPTION |
+---------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> create database abc;
ERROR 1006 (HY000): Can't create database 'abc' (errno: 13)
Here is my users table.
mysql> select host, user from mysql.user;
+-------------+-------+
| host | user |
+-------------+-------+
| % | admin |
| 127.0.0.1 | root |
| ::1 | root |
| IVM-MMC-DGW | root |
| localhost | admin |
| localhost | root |
+-------------+-------+
6 rows in set (0.00 sec)
mysql> show grants;
+-----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for admin@localhost |
+-----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY PASSWORD '*4ACFE3202A5FF5CF467898FC58AAB1D615029441' WITH GRANT OPTION |
+-----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
I can create and remove table in the existing database.
The data directory already has mysql:mysql privileges and also the logged in user has privilege to create the new database.
What configuration is missing here ?
回答1:
There may be a permissions issue with the MySQL data directory. You could try setting the permissions as follows (adjust the path to your data directory)
chown -R mysql:mysql /usr/local/mysql/data
回答2:
This happens probably due to permission denied by MySQL. Though you set the datadir=/drbd0/mysql/data
, but by default MySql set socket = /var/lib/mysql/mysql.sock
, so you should have the privileges to that directory.
less /etc/group
and then
less /etc/passwd
find mysql user and group name, by default, it's mysql user in mysql group.
change to mysql dir, probably /var/lib/mysql
and then type cd ..
to go up one directory.
chown -R mysql:mysql ./mysql/
Replace mysql:mysql
with something different if you group and user privileges are called differenty
回答3:
It might be problem with space. Follow this
- Check .err logs at /var/lib/mysql
if the log says something like "[ERROR] Can't start server: can't create PID file: No space left on device"
Check /var size by df -hk /var
if used is 100% , then u have to find the files which is geting filled.
find large file in /var by find /var/ -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
see which file you can delete and then restart the mysql process by
- /etc/init.d/mysql restart
let me know if that worked :)
回答4:
For Mac OS use this command
sudo chown -R mysql:mysql /usr/local/mysql*
User mysql
should have write access to mysql data directory.
回答5:
sudo chown -R mysql:mysql /var/lib/mysql/
回答6:
In /etc/mysql/my.cnf, set datadir = /home/mysql_data, which is the location where the database files actually are on yourmachine
回答7:
if you move the mysql folder you restart mysql, it works
回答8:
Turn off SELinux especially if you're on CentOS.
Check Turning off or disabling SELinux.
回答9:
Check your mysql data directory permissions.
The data directory is configured in '/etc/my.conf' by default.
Or usemysqladmin -uroot -p variables | grep datadir
to find the directory.
It may be/var/lib/mysql/
by default, and makesure the owner user and group is mysql.chown -R mysql:mysql /usr/local/mysql/data
If it has not been solved by step 1. It may be because of
SELinux
in your way, try to turn off it.- Test if SELinux is running.
selinuxenabled && echo enabled || echo disabled
- Turning off SELinux temporarily.
echo 0 > /selinux/enforce
- Completely turning off SELinux. Change config
SELINUX=disabled
, and reboot.
In different os, the configuration directory of
SELinux
may be different.- Test if SELinux is running.
回答10:
Same issue, in my case I changed the default directory on my.cf and the selinux has blocking it.
To test:
setenforce 0
To fix (CentOS)
Add context and make it permanent
semanage fcontext -a -s system_u -t mysqld_db_t "/var/data/mysql(/.*)?" restorecon -Rv /var/data/mysql
source: https://naveensnayak.wordpress.com/2016/01/14/changing-mysql-data-directory-centos-7/
回答11:
Running WAMP and i had same issue, opted for the traditional stop and start all services and that did it for me. I was able to create the database after that, really don't know why i wasn't able to create it at first as i had no issue with space or permission. Well i hope this helps the WAMP users
回答12:
In my case this was a problem with owner of MySQL data directory, as suggested by the others. However the setup on my server was quite uncommon, using different directories, so here is more detailed solution:
- Find MySQL data directory
grep 'datadir' $(find /etc -iname my.cnf 2>/dev/null) | awk '{print $3}'
If MySQL configuration is in correct place, it returns e.g. /var/lib/mysql
If it doesn't return any result, try to search in the whole filesystem using
grep 'datadir' $(find / -iname my.cnf 2>/dev/null) | awk '{print $3}'
(this may take a long time)
Break down:
find /etc -iname my.cnf 2>/dev/null
finds a file named my.cnf in /etc
ignoring errors
grep 'datadir' /etc/mysql/my.cnf
finds datadir in the file found in the previous step
awk '{print $3}'
prints the third column from the standard input
- Fix the ownership
sudo chown -R mysql:mysql MYSQLDIR
replacing MYSQLDIR
with the path to the directory returned in step 1
来源:https://stackoverflow.com/questions/18719748/error-1006-hy000-cant-create-database-errno-13-mysql-5-6-12