mv directory and contents to new directory

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

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/.

Tags:

Mv