mysql> 创建数据库测试;错误 1006 (HY000):无法创建数据库 'test' (errno: 2)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19120771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:01:29  来源:igfitidea点击:

mysql> create database test; ERROR 1006 (HY000): Can't create database 'test' (errno: 2)

mysql

提问by user2827592

I can't create a database after logging in mysql under my root account. Do I have to make an admin account to do so? Also, for some reason, my StartUp file didn't install (there was an error). I'm not sure if that will affect anything else since mySQL DOES start up when I type "mysql" into my terminal.

在我的 root 帐户下登录 mysql 后,我无法创建数据库。我是否必须创建一个管理员帐户才能这样做?此外,由于某种原因,我的 StartUp 文件没有安装(出现错误)。我不确定这是否会影响其他任何事情,因为当我在终端中键入“mysql”时 mySQL 会启动。

Also when I type in

当我输入时

mysql> SELECT Host, User FROM mysql.user;
+---------------------+------+
| Host                | User |
+---------------------+------+
| 127.0.0.1           | root |
| ::1                 | root |
| myname-mac.att.net  |      |
| myname-mac.att.net  | root |
| localhost           |      |
| localhost           | root |
+---------------------+------+

Which I don't get. I seem to have multiple root users and I don't know what ::1 means.

我不明白。我似乎有多个 root 用户,但我不知道 ::1 是什么意思。

EDIT: My databases currently look like this.

编辑:我的数据库目前看起来像这样。

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.02 sec)

And it doesn't matter what I type in as my database name. I even tried calling it 'apple'.

我输入什么作为我的数据库名称并不重要。我什至尝试称它为“苹果”。

回答by sandejai

It might be problem with space. Follow this

可能是空间问题。按照这个

  1. Check .err logs at /var/lib/mysql
  2. if the log says something like "[ERROR] Can't start server: can't create PID file: No space left on device"

  3. Check /var size by df -hk /var

  4. if used is 100% , then u have to find the files which is geting filled.

  5. find large file in /var by

    find /var/ -type f -size +100000k -exec ls -lh {} \; | awk '{ print  ": "  }'
  6. see which file you can delete and then restart the mysql process by

  7. /etc/init.d/mysql restart
  1. 检查 .err 日志 /var/lib/mysql
  2. 如果日志显示类似“[错误] 无法启动服务器:无法创建 PID 文件:设备上没有剩余空间”

  3. 检查 /var 大小 df -hk /var

  4. 如果使用的是 100% ,那么你必须找到被填满的文件。

  5. 在 /var 中查找大文件

    find /var/ -type f -size +100000k -exec ls -lh {} \; | awk '{ print  ": "  }'
  6. 查看您可以删除哪个文件,然后通过以下方式重新启动 mysql 进程

  7. /etc/init.d/mysql restart

let me know if that worked :)

让我知道这是否有效:)

回答by Varun Natraaj

If you're on macosx and if you've system preference pane installed, that should show a message like

如果您使用的是 macosx 并且安装了系统首选项窗格,则应显示如下消息

the following directory is not owned by _mysql user - "/usr/local/msyql/data"

Once you know that path you can do the following:

知道该路径后,您可以执行以下操作:

sudo chown -R mysql:mysql /usr/local/mysql/data

sudo chown -R mysql:mysql <path>

回答by AdrianBR

You have one root user for several domains. Meaning you can connect and run queries on that database FROM the specified domains.

您有多个域的一个 root 用户。这意味着您可以从指定的域连接并对该数据库运行查询。

If you want to only show one, give it '%' for the domain and remove all others, although that is not advised. Save the root user for run rights only from localhost, and create limited users for running queries from outside.

如果您只想显示一个,请为域指定 '%' 并删除所有其他域,尽管不建议这样做。将 root 用户保存为仅从 localhost 运行权限,并为从外部运行查询创建受限用户。

As for test database error, it happens on fresh installs. Just reboot the mysql server(stop/start process) or the computer.

至于测试数据库错误,它发生在全新安装上。只需重新启动 mysql 服务器(停止/启动进程)或计算机。

Also, make sure you have full rights by doing

另外,请确保您拥有完整的权利

GRANT ALL PRIVILEGES ON *.* TO 'root'@'thedomainyourunfrom/localhost/%' WITH GRANT OPTION;

this will give your root user full rights across all databases in the server

这将为您的 root 用户提供对服务器中所有数据库的完全权限

osx manual http://dev.mysql.com/doc/mysql-macosx-excerpt/5.0/en/macosx-installation.html

osx 手册http://dev.mysql.com/doc/mysql-macosx-excerpt/5.0/en/macosx-installation.html

回答by Heitor Castro

As an additional resource, you can try two other things:

作为附加资源,您可以尝试另外两件事:

  1. Find out the data folder for your MySQL and 'chown' it so that mysql can write properly to it. For example, if your MySQL's data folder is /usr/local/mysql/data/, you can 'chown' it by typing up the command chown -R mysql:mysql /usr/local/mysql/data/

  2. If you have just installed your MySQL server, try restarting your computer. Sometimes the installer fails on giving proper file access to the program

  1. 找出您的 MySQL 的数据文件夹并“chown”它,以便 mysql 可以正确地写入它。例如,如果你的 MySQL 的数据文件夹是 /usr/local/mysql/data/,你可以通过输入命令来“chown”它chown -R mysql:mysql /usr/local/mysql/data/

  2. 如果您刚刚安装了 MySQL 服务器,请尝试重新启动计算机。有时安装程序无法为程序提供适当的文件访问权限

I hope that helps!

我希望这有帮助!