Error dropping database in SQL (can't rmdir './tract', errno: 66)

11,552

Solution 1

Find the DB directory first using command

mysql -e "select @@datadir"

It will return your database directory e.g.

+-----------------------+
| @@datadir             |
+-----------------------+
| /usr/local/var/mysql/ |
+-----------------------+

Goto that directory and delete the database using command

rm -rf DB_name

You can root user too using command

sudo rm -rf DB_name

Solution 2

It looks like you may have lost some files, which would explain why mysql says the db exists, but you can't delete it due to file not found errors.

There are entries in the system db for database objects and if some files go away (are deleted or whatever) you can't just DROP [database] if this happens.

Check here for the answer.

Solution 3

Please take a look at this post:

how to drop database

Seems that there are some not mysql files inside tract directory.

Share:
11,552
Divine Davis
Author by

Divine Davis

Computer Science Senior @ Claflin University

Updated on June 27, 2022

Comments

  • Divine Davis
    Divine Davis almost 2 years

    I am trying to drop the database and create it again, obviously, but it will not work.

    It gives me the error:


    mysql> source /Users/divinedavis/downloads/tract_schema.sql;

    ERROR 1010 (HY000): Error dropping database (can't rmdir './tract', errno: 66)

    ERROR 1010 (HY000): Can't creat database 'TRACT'; database exits

    Database changed

    DROP DATABASE IF EXISTS TRACT;
    CREATE DATABASE TRACT;
    USE TRACT;
    
    # # is used for comment in MySQL
    #DROP TABLE employee; 
    
    CREATE TABLE CUSTOMER (
      cust_num   integer(10),
      cf_name varchar(15), 
      cm_init   varchar (2),
      cl_name varchar(15),
      c_address   varchar (40),
      c_uname varchar(15),
      primary key (cust_num, cf_name, cl_name)  
    );
    
    CREATE TABLE INVOICE (
      inum    integer(10) not null, 
      i_date    date default null,
      custf_name   varchar(15),
      cl_name varchar (15) default null,
      tech_uname      varchar(15) default null,
      lp_num    varchar(6) default null,
      primary key (inum)
    );
    
    #DROP TABLE department; #CASCADE CONSTRAINTS;
    CREATE TABLE PAYMENT (
      p_type        varchar(25) not null,
      i_num      integer(10),
      amount       decimal(5,2), 
      foreign key (i_num) references invoice(inum)
    );
    
    #ALTER TABLE employee ADD(
    #foreign key (dno) references department(dnumber)
    
    #);
    
    #DROP TABLE dept_locations; #CASCADE CONSTRAINTS;
    
    
    #DROP TABLE project; #CASCADE CONSTRAINTS;
    CREATE TABLE VEHICLE (
      model      varchar(25) not null,
      lp_num    varchar (6) not null,
      vin  varchar(17),
      v_year       integer(4) not null,
      v_trim      varchar(10) not null,
      tire_size    varchar(6),
      make  varchar(15),
      mileage       integer(8) not null,
      color varchar(20),
      cust_name varchar(30),
      primary key (lp_num, vin)
    );
    
    #DROP TABLE works_on; #CASCADE CONSTRAINTS;
    CREATE TABLE TECHNICIAN (
      wage   decimal(3, 2),
      s_name    varchar (23),
      s_num  integer,
      city   varchar(20),
      state    varchar (20),
      zip  integer,
      reviews   varchar(400),
      ratings   integer (5),
      tf_name  varchar(10),
      tm_init   varchar(2),
      tl_name    integer (4),
      t_uname  varchar(15),
      t_ssn integer(9),
      primary key (t_uname)
    );
    
    #DROP TABLE dependent; #CASCADE CONSTRAINTS;
    CREATE TABLE CREDENTIALS (
      email           char(9),
      username varchar(15),
      user_password       char,
      ssn integer(9),
      primary key (username)
      );
    
    CREATE TABLE RT_CALENDAR (
      time_of_operation    integer(9),
      date_of_repair date
    );
    
    CREATE TABLE WORKS_ON (
      cost           decimal(3,2),
      hours integer(15),
      lp_num            char,
      t_ssn          date
    );
    
  • Adrián
    Adrián about 8 years
    Be careful. You may delete some important files which are unrelated to mysql.
  • Divine Davis
    Divine Davis about 8 years
    I'm using Mac. Is there a way I can delete it through the finder?
  • Divine Davis
    Divine Davis about 8 years
    How did he get this 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 to pop up?
  • Adrián
    Adrián about 8 years
    You should first check what files are on that directory, before removing it.