MySQL 删除数据库时出错(无法 rmdir '.test\',错误号:17)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4584458/
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 18:11:30  来源:igfitidea点击:

Error Dropping Database (Can't rmdir '.test\', errno: 17)

mysqlsqlphpmyadmin

提问by Sid

Basically, I was taught on how to create a root password using the "mysqladmin -u root -p password" command, this was done all through the windows command editor. Now, the next process was to display the default databases (info. schema, mysql and test) which was achieved by using "SHOW DATABASES;"

基本上,我学会了如何使用“mysqladmin -u root -p password”命令创建 root 密码,这完全是通过 Windows 命令编辑器完成的。现在,下一个过程是显示默认数据库(info.schema、mysql 和 test),这是通过使用“SHOW DATABASES;”实现的。

But according to the book, we had to delete the redundant test file and the following error pops up:

但是根据书上的说法,我们不得不删除多余的测试文件,然后弹出以下错误:

Error Dropping Database (Can't rmdir '.test\', errno: 17)

删除数据库时出错(无法 rmdir '.test\',错误号:17)

The command put to use was DROP DATABASE test;

使用的命令是 DROP DATABASE test;

I am using MYSQL and PHPMYADMIN. Any help on how to drop the file with no errors?

我正在使用 MYSQL 和 PHPMYADMIN。有关如何无错误地删除文件的任何帮助?

回答by Shakti Singh

A database is represented by a directory under the data directory (usually /var/lib/mysql), and the directory is intended for storage of table data.

数据库由数据目录(通常为/var/lib/mysql)下的一个目录表示,该目录用于存储表数据。

The DROP DATABASEstatement will remove all table files and then remove the directory that represented the database. It will not, however, remove non-table files, whereby making it not possible to remove the directory.

DROP DATABASE语句将删除所有表文件,然后删除代表数据库的目录。但是,它不会删除非表文件,从而无法删除目录。

MySQL displays an error message when it cannot remove the directory

MySQL 在无法删除目录时显示错误消息

you can really drop the database manually by removing any remaining files in the database directory and then the directory itself.

您可以通过删除数据库目录中的任何剩余文件然后删除目录本身来手动删除数据库。

回答by Beel

I ran into this same issue on a new install of mysql 5.5 on a mac. I tried to drop the test schema and got an errno 17 message. errno 17 is the error returned by some posix os functions indicating that a file exists where it should not. In the data directory, I found a strange file ".empty":

我在 mac 上新安装 mysql 5.5 时遇到了同样的问题。我尝试删除测试模式并收到 errno 17 消息。errno 17 是一些 posix os 函数返回的错误,表明文件存在于它不应该存在的地方。在数据目录中,我发现了一个奇怪的文件“.empty”:

sh-3.2# ls -la data/test
total 0
drwxr-xr-x   3 _mysql  wheel  102 Apr 15 12:36 .
drwxr-xr-x  11 _mysql  wheel  374 Apr 15 12:28 ..
-rw-r--r--   1 _mysql  wheel    0 Mar 31 10:19 .empty

Once I rm'd the .empty file, the drop database command succeeded.

一旦我 rm'd .empty 文件,drop database 命令就成功了。

I don't know where the .empty file came from; as noted, this was a new mysql install. Perhaps something went wrong in the install process.

我不知道 .empty 文件来自哪里;如前所述,这是一个新的 mysql 安装。也许安装过程中出了点问题。

回答by Nerve

Go to the datadir for your mysql installation and rm the databases manually. It can be

转到 mysql 安装的 datadir 并手动 rm 数据库。有可能

/usr/local/var/mysql

Then,

然后,

rm -R <Your DB name>

To check datadir for your installation,

要检查安装的 datadir,

vim the mysql.server file and find it there.

回答by Floccinaucinihilipilification.

For phpmyadmin, go to xampp\mysql\dataand simply delete the database folder. Worked for me !!

对于phpmyadmin,转到xampp\mysql\data并简单地删除数据库文件夹。为我工作!!

回答by Nasif Md. Tanjim

If it is XAMPP, Do the following:

如果是XAMPP,请执行以下操作:

cd /opt/lampp/var/mysql;
sudo su;
rm -rf test;

Hope this helps.

希望这可以帮助。

回答by J86

I just ran into this problem with WAMP and the phpMyAdmin that comes with it. To remove the database and make the error go away. I went into C:\wamp\bin\mysql\mysql5.5.24\data\and deleted the folder for the database in question.

我刚刚在 WAMP 和它附带的 phpMyAdmin 中遇到了这个问题。删除数据库并使错误消失。我进入C:\wamp\bin\mysql\mysql5.5.24\data\并删除了相关数据库的文件夹。

Then I refreshed the page at phpMyAdmin, and the database was gone.

然后我刷新了phpMyAdmin的页面,数据库不见了。

回答by IqbalHamid

Just to add to the responses so far: In Windows 10, the data files are kept here...

只是为了添加到目前为止的响应:在 Windows 10 中,数据文件保存在这里...

C:\ProgramData\MySQL\MySQL Server [m.n]\data

C:\ProgramData\MySQL\MySQL 服务器 [mn]\data

There will be directories for each schema in your database. You will want to go inside the schema you are trying to drop, manually delete any superfluous files then try the drop command again.

数据库中的每个模式都有目录。您将想要进入您尝试删除的架构,手动删除任何多余的文件,然后再次尝试删除命令。

Any workbench changes against a database will get stored in this location. For example, I had this error following a reverse engineering exercise on one of my databases and saving the changes which get stored in a .mwb file in this location.

对数据库的任何工作台更改都将存储在此位置。例如,在对我的一个数据库进行逆向工程练习并保存存储在此位置的 .mwb 文件中的更改后,我遇到了此错误。

回答by Mewan

Go through this and remove corresponding cache files in selected db then after you can drop your database

完成此操作并删除所选数据库中的相应缓存文件,然后您可以删除数据库

First find Your MySQL Data Directory Containing Your selected DB

首先找到包含您选择的数据库的 MySQL 数据目录

Linux

Linux

  • Open up MySQL's configuration file: less /etc/my.cnf
  • Search for the term "datadir": /datadir

  • If it exists, it will highlight a line that reads: datadir = [path]

  • You can also manually look for that line. It typically would be found under a section heading of [mysqld] but it does not necessarily have to be found there.

  • If that line does not exist, then MySQL will default to: /var/lib/mysql.

  • 打开 MySQL 的配置文件:less /etc/my.cnf
  • 搜索术语“datadir”:/datadir

  • 如果存在,它将突出显示一行:datadir = [path]

  • 您也可以手动查找该行。它通常可以在 [mysqld] 的部分标题下找到,但不一定必须在那里找到。

  • 如果该行不存在,则 MySQL 将默认为:/var/lib/mysql。

Windows 1. Open up MySQL's configuration file into Notepad: my.ini

Windows 1. 在记事本中打开 MySQL 的配置文件:my.ini

The my.ini will be located in the MySQL program folder, which would be wherever it got installed. If you did not install MySQL, then use the Windows "search" feature to look for my.ini. You could also manually search for it by browsing to [drive]:\Program Files\MySQL\MySQL Server 5.5.

my.ini 将位于 MySQL 程序文件夹中,该文件夹将位于安装它的任何位置。如果您没有安装 MySQL,那么使用 Windows 的“搜索”功能来查找 my.ini。您也可以通过浏览到 [drive]:\Program Files\MySQL\MySQL Server 5.5 来手动搜索它。

  1. Do a search in Notepad to find the term "datadir".

  2. If it exists, it will highlight a line that reads: datadir = [path]

  3. You can also manually look for that line. It typically would be found under a section heading of [mysqld] but it does not necessarily have to be found there.

  4. If that line does not exist, then you'll probably find it under [drive]:\ProgramData\MySQL\MySQL Server 5.5\data.

  1. 在记事本中搜索以查找术语“datadir”。

  2. 如果存在,它将突出显示一行:datadir = [path]

  3. 您也可以手动查找该行。它通常可以在 [mysqld] 的部分标题下找到,但不一定必须在那里找到。

  4. 如果该行不存在,那么您可能会在 [drive]:\ProgramData\MySQL\MySQL Server 5.5\data 下找到它。

NOTE: The "ProgramData" folder may be hidden. You may have to type the explicit path into Windows Explore

注意:“ProgramData”文件夹可能被隐藏。您可能必须在 Windows 资源管理器中键入显式路径

回答by Mansur Ali

You may need to check two things.

您可能需要检查两件事。

1- Database Foleder's permissionThe database you wants to delete must have the same owner as mysql process has.

1-数据库文件夹的权限您要删除的数据库必须与 mysql 进程具有相同的所有者。

2- Directory Must be emptyGoto the mysql data directory and verify that directory is empty

2-目录必须为空转到mysql数据目录并验证该目录为空

After that connect your mysql cli and run drop database command again.

之后连接您的 mysql cli 并再次运行 drop database 命令。

回答by dland

I ran into this problem, and when I checked out the database directory, there were a number of expfiles (the ibdand frmfiles had been removed). Listing the files to look at their attributes (since the owner already had rw privileges on the files)

我遇到了这个问题,当我检查数据库目录时,有很多exp文件(ibdfrm文件已被删除)。列出文件以查看其属性(因为所有者已经对文​​件具有 rw 权限)

lsattr *.exp
-------------e-- foo.exp
-------------e-- bar.exp

Man page says

手册页说

       The  'e'  attribute  indicates that the file is using extents for mapping the blocks on disk.
       It may not be removed using chattr(1).

You actually can chattr -ethese files, but mysql still won't let you drop the database. Removing the files with rm, however, allows the database to be dropped cleanly.

您实际上可以使用chattr -e这些文件,但 mysql 仍然不会让您删除数据库。rm但是,使用删除文件允许干净地删除数据库。