root@username:/var/lib/mysql/my_db# ll *.ibd|wc
12411167941
root@username:/var/lib/mysql/my_db# mysql -e "show tables from my_db" \
| grep -v Tables_in_my_db \
| while read a; do mysql -e "ALTER TABLE my_db.$a DISCARD TABLESPACE"; done
root@username:/var/lib/mysql/my_db# ll *.ibd|wc
ls: cannot access '*.ibd': No such file or directory
000
可以看到所有的 .idb 文件都已经被抛弃了。然后把旧的有数据的 .ibd 文件拷贝到这个 my_db 目录下面,别忘了把属主改过来:chown mysql. *,再把这些数据文件 import 到数据库中。root@username:/var/lib/mysql/my_db# mysql -e "show tables from my_db" \
| grep -v Tables_in_my_db \
| while read a; \
do mysql -e "ALTER TABLE my_db.$a import TABLESPACE"; done