Wednesday, December 4, 2024

Guide: Keeping Your MariaDB Data on an External Drive on Ubuntu

Share

If you’re looking to up your game with MariaDB data storage, then you’ve come to the right place. This guide will show you how to safely keep your MariaDB data on an external drive while using Ubuntu. Buckle up as we step up your MariaDB knowledge in a big way!

MariaDB, as most of you might already know, is one of the most popular database servers in the world. It’s a powerful, robust and free open-source relational database management system developed by the original developers of MySQL.

This guide assumes you already have MariaDB installed on your Ubuntu system. If not, you can install it by following the official guide here.

Getting Started

Step 1: Backup Your MariaDB Database

Before moving any data, it’s crucial to back up your current database. This is an important safety measure to prevent any data loss. You can use the mysqldump command like so:

mysqldump -u root -p --all-databases > alldb.sql

Step 2: Stop MariaDB Service

Before moving your database files to the external drive, make sure the MariaDB service is stopped.

sudo systemctl stop mariadb

Step 3: Copy MariaDB Data Directory to External Drive

Now, copy the entire MariaDB data directory to your external drive. The default directory is usually /var/lib/mysql. Replace ‘/path/to/external/drive’ with the actual path where you want the data to be stored.

sudo cp -R /var/lib/mysql /path/to/external/drive

Step 4: Rename or Remove the Old MariaDB Directory

We want to ensure MariaDB uses the new directory. To prevent it from using the old one, rename or remove it.

sudo mv /var/lib/mysql /var/lib/mysql-old

MariaDB will still look for the data in the old path, so we’ll create a symbolic link to the new directory.

sudo ln -s /path/to/external/drive/mysql /var/lib/mysql

Step 6: Set the Correct Permissions

We need to ensure MariaDB has the right permissions to read and write data to the new directory. To set these permissions, use the chown command:

sudo chown -R mysql:mysql /path/to/external/drive/mysql

Step 7: Start MariaDB Service

Now you can start the MariaDB service again:

sudo systemctl start mariadb

Step 8: Test Your New Setup

Test your new setup to confirm everything is working as expected:

mysql -u root -p -e "SHOW DATABASES;"

You should see a list of your databases, which confirms that MariaDB is now reading data from the new location on the external drive.

Conclusion on Using MariaDB from an External Drive

And there you have it! You’ve successfully moved your MariaDB data to an external drive on Ubuntu. Now you have a much more flexible and scalable database setup that can accommodate larger data sets and grow as your needs do.

Remember to backup your database regularly and ensure the external drive is always connected when MariaDB service is running.

If you have any questions or run into any issues, don’t hesitate to check out the MariaDB’s official documentation or Ubuntu’s community help pages.

Key Takeaways:

  • It’s critical to backup your data before moving it.
  • You have to stop the MariaDB service before moving the data.
  • Linking the new data directory to the old path is crucial.
  • Don’t forget to set the correct permissions for the new directory.
  • Make sure to test your new setup to ensure it works as expected.

Happy data managing, folks!

Related Articles

Read more

Local News

Simple, privacy focused and free ad network for websites in need of new visitors. Free & easy backlink link building. Copyright ©   2024 producent suplementów diety, produkcja kontraktowa suplementów diety ioc.