This post was published in 2016 and may contain information, techniques or code examples that are no longer current. Please double-check official documentation and modern best practices before using anything from this article.
Putting this together because I always end up checking online for the correct bash commands for Linux. These commands rely on your knowing for sure which database is which and you should always double check to be sure.
Export
First step is to go to use cd to change directory to the one in which you want the SQL Dump to appear. The dump will consist of a text file and all the database structure and content included.
cd var/www/example.com
If you want to double check the contents of the directory you are in then simply enter ls and a list of directories and files will be returned.
ls
When you’re happy you’re in the right directory, we can export the file. In this instance I have a user name (user123) after the -uand the database is database_live and the initial -p means bash will ask me for the password.
mysqldump -p -uuser123 database_live > mydumpfile.sql
Hit enter, enter the password and after some serious thinking (depending on the size of the database) you’ll be able to enter the next command. Again, entering ls will allow you to verify there is a file called mydumpfile.sql in the directory.
Import
The next step is then to import the database into your other database. It should be noted that importing the previous dump will with default configuration wipe any existing data during the import into the second database.
In the instance below I have a user name (uuser456 ) after the -uand the database is database_live and the initial -p means bash will ask me for the password.
mysql -p -uuser456 database_backup < mydumpfile.sql
Hit enter, enter the password for the user and again it will hang while the details are imported.
Latest posts
—
Core Web Vitals: Optimisation techniques
Google's Core Web Vitals have become the de facto standard for measuring user experience on the web. For years, developers have focused on the foundational trio: Largest Contentful Paint (LCP),…
Continue reading "Core Web Vitals: Optimisation techniques "
—
Web Safe Fonts: A Quick Explainer for Developers
If you've ever built a website and wondered why your carefully chosen typography looks completely different on someone else's screen, you've encountered the world of web safe fonts. Let's break…
Continue reading "Web Safe Fonts: A Quick Explainer for Developers "
—
Choosing the right content management system
Choosing the right content management system (CMS) is one of the most consequential early decisions when building a website The content management system shapes everything from how editors publish to…
Continue reading "Choosing the right content management system"
—
WYSIWYG or plain-text CMS editing?
Finding the Right Balance for Your CMS UsersWhen configuring a content‑management system (CMS), the choice between a WYSIWYG (What‑You‑See‑Is‑What‑You‑Get) editor and a plain‑text interface has far‑reaching implications for both usability…