mysql source命令给出错误2和错误17?

时间:2013-07-29 04:42:17

标签: mysql database

当我在cmd中尝试此命令时:

SOURCE D:\books.sql;

我收到此错误:

错误: 无法打开文件'D:\ books.sql;',错误:2

我在网上搜索了这个,到目前为止我发现这个错误不知何故意味着没有这样的文件或目录! 但我很确定我的档案就在那里! 感谢。

这是books.sql中的代码:

DROP DATABASE IF EXISTS books;

CREATE DATABASE books;

USE books;

CREATE TABLE Authors
(
   AuthorID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   FirstName varchar(30) NOT NULL,
   LastName varchar(30) NOT NULL
)                 ;
CREATE TABLE Titles
(
   ISBN varchar(20) NOT NULL PRIMARY KEY,
   Title varchar(100) NOT NULL,
   EditionNumber int NOT NULL,
   Copyright varchar(4) NOT NULL
)             ;

CREATE TABLE AuthorISBN
(
   AuthorID int NOT NULL,
   ISBN varchar(20) NOT NULL,
   FOREIGN KEY (AuthorID) REFERENCES Authors(AuthorID),
   FOREIGN KEY (ISBN) References Titles(ISBN)
)            ;

INSERT INTO Authors (FirstName,LastName) VALUES ('Paul','Deitel')           ;
INSERT INTO Authors (FirstName,LastName) VALUES ('Harvey','Deitel')     ;
INSERT INTO Authors (FirstName,LastName) VALUES ('Abbey','Deitel')     ;
INSERT INTO Authors (FirstName,LastName) VALUES ('Michael','Morgano')    ;
INSERT INTO Authors (FirstName,LastName) VALUES ('Eric','Kern')     ;


INSERT INTO Titles (ISBN,Title,EditionNumber,Copyright) VALUES ('0132152134','Visual Basic 2010 How to Program',5,'2011')          ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (1,'0132152134')     ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (2,'0132152134') ;

INSERT INTO Titles (ISBN,Title,EditionNumber,Copyright) VALUES ('0132151421','Visual C# 2010 How to Program',4,'2011')  ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (1,'0132151421')      ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (2,'0132151421')      ;

INSERT INTO Titles (ISBN,Title,EditionNumber,Copyright) VALUES ('0132575663','Java How to Program',9,'2012')   ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (1,'0132575663')                                               ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (2,'0132575663')                                       ;

INSERT INTO Titles (ISBN,Title,EditionNumber,Copyright) VALUES ('0132662361','C++ How to Program',8,'2012')     ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (1,'0132662361')                                                  ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (2,'0132662361')                                                 ;

INSERT INTO Titles (ISBN,Title,EditionNumber,Copyright) VALUES ('0132404168','C How to Program',6,'2010')     ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (1,'0132404168')                                             ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (2,'0132404168')                                       ;

INSERT INTO Titles (ISBN,Title,EditionNumber,Copyright) VALUES ('013705842X','iPhone for Programmers: An App-Driven Approach',1,'2010')        ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (1,'013705842X')                                                    ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (2,'013705842X')                                                    ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (3,'013705842X')                                                    ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (4,'013705842X')                                                    ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (5,'013705842X')                                                    ;

INSERT INTO Titles (ISBN,Title,EditionNumber,Copyright) VALUES ('0132121360','Android for Programmers: An App-Driven Approach',1,'2012')        ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (1,'0132121360')                                                    ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (2,'0132121360')                                                    ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (3,'0132121360')                                                    ;
INSERT INTO AuthorISBN (AuthorID,ISBN) VALUES (4,'0132121360')                                                    ;

所以在中间我没有用分号测试它,这是结果:

ERROR 1010 (HY000): Error dropping database (can't rmdir '.\books\', errno: 17)

似乎因为第1行而发生此错误。 现在做什么?

1 个答案:

答案 0 :(得分:1)

既然你已经自己回答了“来源问题”,我会尝试帮助第二部分。

内部mysql数据库由目录表示,在此目录中由数据库文件表示。现在,当您删除数据库时,mysql首先删除文件,最后一步将删除该目录。

现在有两种情况可能导致错误17:

  1. 该目录的权限不足
  2. 不受mysql管理的剩余文件
  3. 所以我会执行以下步骤:首先检查您对该目录的权限,如果您确定它们没问题,请尝试再次运行您的示例。如果这不起作用,请检查目录path/to/mysql/books中是否有与mysql无关的文件并手动删除它们。在此之后,您应该能够执行DROP DATABASE IF EXISTS books;命令。