Restore MySQL database from Dump File Command Line Linux Ubuntu

To restore and backup your MySQL database from mysqldump file, Simply type the MySQL command mysql -u [user] -p [database_name] [mysqlDumpFile].sql on the Linux Ubuntu command line and press enter, and it will restore the database from the dump file.

Suppose you want to backup your MySQL database, but the size of your database is more than 3GB, in that case, you will not be able to import and export the database, for this, you have to use a mysqldump file of the MySQL database, which you can use the MySQL command mysql -u [user] -p [database_name] [mysqlDumpFile].sql on the command line to create backup MySQL database file and easily restore it with the help of this file.

How to Restore MySQL database from mysqlDump File using Command Line Linux Ubuntu

Here are some steps to backup and restore MySQL database from a dump file using the command line on Linux Ubuntu:

Step 1: Check your MySQL version

To check the MySQL version, Simply type MySQL -v command on the command line or prompt, and press enter, it will show you MySQL version:

mysql -V

Step 2: Create a new database

If you don’t already have a database to restore your data, you’ll need to create one. You can create MySQL database with the help of the mysql -u root -p -e "db" command:

mysql -u root -p -e "create database yourdatabase;"

Replace ‘yourdatabase‘ with the name you want to give your database.

Step 3: Move mysqldump file to Server

Before restoring a MySQL database from a mysqldump file, move your MySQLdump file to another server, or download it to a local system, and you can do this by typing the SCP command at the command line:

scp /path/to/dump.sql [email protected]:/path/on/server

In the above-given command, Replace ‘/path/to/dump.sql’ with the path to your dump file, ‘username’ with your username, ‘your.server.example.com’ with the IP address or domain name of your server, and ‘/path/on/server’ with the path where you want to store your dump file on your server.

Step 4: MySQL Restore the database from the MySQL dump file Linux Ubuntu

To restore MySQL database from mysqldump file, Just type the mysql command mysql -u [user] -p [database_name] < [mysqldump].sql on Linux Ubuntu command line, which you can use like this:

mysql -u root -p yourdatabase < /path/on/server/dump.sql

In the above-given command, replace ‘yourdatabase‘ with the name of the database you created in step 2, and ‘/path/on/server/dump.sql’ with the path to your dump file on your server.

If the mysql database dump file is compressed, in that case, just type gunzip < /path/to/dumpfile.sql.gz | mysql -u root -p database command on the command line to unzip or extract to restore the mysql database from the dump file, which you can use like this:

gunzip < /path/to/dumpfile.sql.gz | mysql -u root -p yourdatabase

The above-given command will decompress the dump file and restore it to the specified database.

Step 5: Verify the restore

Now you need to login to your MySQL server, which you can do with the help of mysql -u root -p command:

mysql -u root -p

Now you are logged in mysql server, you can verify whether your database was restored or not by typing the use yourdatabase; command on the command line:

use yourdatabase;

In the above-given command, Replace ‘yourdatabase’ with the name of your database.

MySQL Restore database from MySQL Dump File Command Line Linux Ubuntu:

Conclusion

With the help of the tutorial, you learned how to restore MySQL database from mysqldump file using the command line or terminal on linux ubuntu server.

Recommended Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *