6

I have a directory: /var/lib/mysql/test_db/ which contains numerous files that make up the test_db database

I have now created a new directory: /var/lib/mysql/data/

I am trying to move the test_db directory and it's contents into the data directory.

I've tried various commands revolving around

sudo mv /var/lib/mysql/test_db/ /var/lib/mysql/data/test_db/

But I keep getting the error:

mv: cannot move /var/lib/mysql/test_db/ to /var/lib/msyql/data/test_db/: No such file or directory

But if I run: ls -lah

I get

drwxrwxrwx  2 root  root    32K Mar 27 15:58 test_db
drwxrwxrwx  3 mysql mysql  4.0K Mar 30 10:51 data

which from what I can tell means they are both directories, and therefore both exist.

As you can see I have changed permissions on them both (chmod 777 test_db), but that didn't work.

What am I missing?

  • you are missing the subdirectory /var/lib/msyql/data create it or use roaima's answer – Skaperen Mar 30 '15 at 10:14
  • an alternative is to hardlink the files ... then you can use cp -al ... – Skaperen Mar 30 '15 at 10:16
9

Remove the target database directory and move the test_db directory itself. (This will implicitly move its contents, too.)

sudo rmdir /var/lib/mysql/data/test_db
sudo mv /var/lib/mysql/test_db /var/lib/mysql/data

Generally you don't need to provide a trailing slash on directory names.

Reading your comments, if you find that you're still getting a "no such file or directory" error, it may be that your source directory, test_db has already been moved into the target test_db directory (giving you /var/lib/mysql/data/test_db/test_db/...). If this is the case then the rmdir above will also fail with a "no such file or directory" error. Fix it with this command, and then re-run the two at the top of this answer:

sudo mv /var/lib/mysql/data/test_db/test_db /var/lib/mysql/data
| improve this answer | |
  • cheers, that must be the only variation I didn't try. I guess because I was using mv to rename files I got in the habit of always declaring it in both parts of the mv statement. – IGGt Mar 30 '15 at 10:18
5

Your command:

sudo mv /var/lib/mysql/test_db/ /var/lib/mysql/data/test_db/

is for moving /var/lib/mysql/test_db/ inside /var/lib/mysql/data/test_db/, and end up with /var/lib/mysql/data/test_db/test_db/. But as /var/lib/mysql/data/test_db/ does not exist, you're getting an error.

You should run:

sudo mv /var/lib/mysql/test_db/ /var/lib/mysql/data/

to have /var/lib/mysql/test_db/ moved inside /var/lib/mysql/data/.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.