It’s bad idea to run MySQL server on microSD card because usually this type of application will be heavy on read/write cycles and this will effect the lifespan of the sd card. Plus depending on the type of card you are using the external hard drive will be faster. There are two ways to do it. First move files to external drive and change data dir variable or creating symlink. We will use the latter (How to set up MySQL on Raspberry Pi).
- Stop the mysql server:
sudo service mysql stop
- Backup the database:
sudo cp -Rp /var/lib/mysql/ /var/lib/mysql.back/
- Next we will copy our mysql folder to external drive:
sudo cp -Rp /var/lib/mysql /mnt/usbstorage/raspberry/mysql
- Delete the original mysql folder:
sudo rm -r /var/lib/mysql
- Now create symbolic link, first will be destination and second part is the link “sudo ln -s DESTINATION LINK”:
sudo ln -s /mnt/usbstorage/raspberry/mysql /var/lib/mysql
- Finally restart the mysql server:
sudo service mysql start
If everything went smoothly you can log in to your server.
Leave a Reply