Restore a single table from a full mysqldump file
Note: This article assumes that you have installed and configured MySQL® on your server.
Prerequisites
- A MySQL® server
- Access to a MySQL® privileged user such as root.
- A MySQL® dump file of the database that includes the table that you want to import.
Procedure
- Login into your MySQL® server.
Note: This step can change depending on your OS and user type.mysql -u root -p
- Create a temporary database.
CREATE DATABASE tempdatabase;
- Exit the MySQL® server.
exit;
- Go to the MySQL® dump file directory and execute the following command:
mysql -u root -p tempdatabase < mysqldump.sql
- Login into your MySQL® server to ensure that your database was imported properly and the table exists. (Optional)
Login into your MySQL® server.Switch to the temporary database and show the tables:mysql -u root -p
USE tempdatabase; SHOW TABLES; exit;
- Export the desire table to a MySQL® dump.
mysqldump -u root -p tempdatabase mytable > mytabledump.sql
- Import the table to the database.
mysql -u root -p mydatabase < mytabledump.sql
- Delete the temporary database.
Login into your MySQL® server.Delete the database:mysql -u root -p
DROP DATABASE tempdatabase; exit;
Updated 12 months ago