Bash – MySQL Backup Script

Looking for a script to backup your MySQL databases on a Linux host? Here is a simple bash script that can be used to automate the process in a cron job. The script checks the database integrity then dumps the database to a text file, tar’s it up, and the emails a confirmation of completion.




Gentoo – MYSQL Database Server

In this guide I will discuss how to setup a basic MySQL database server on Gentoo.

To install MySQL on your Gentoo system log in as root and type

This will take some time to compile so you may wanna go grab a snack and watch some TV or something.

15 to 30 mins later …

Once the compile finishes type the following line and press enter: (note: where the * is don’t type the * but use the tab key so it auto fills in the right version.)

This will configure MySQL and prompt you to set the root password for the MySQL server to use. This does not have to be the same password you used for your root Gentoo user. It can be any thing you want.

Now start the server by typing:

Then set it to the default runlevel by typing:

Now let’s test the new MySQL install. In a terminal type:

(Note: you can issue this command as your regular user.) It will then prompt you for your MySQL root password. Enter the password and press enter. You should now see the following in your terminal:

  • Select the MySQL database:
  • View the MySQL database’s existing tables:
  • List the users:

After issuing the last command it will spew up a bunch of characters and stuff on the screen, but there should be no errors. If there are no errors your install was a success! Type to exit the MySQL command line interface.

Now we need to set the mysql use flag in our /etc/make.conf file. I know you read the handbook so you know exactly what I am talking about right? Well to review, you need to add mysql to your use flag list so that when you compile packages that need to use it, it automatically sets that flag and compiles MySQL support into the package. Here is how we add it. As root do the following:

  • You should now be looking at your make.conf file which you created during your initial install when you followed the handbook. In this file you have a line that reads:
  • Maybe you have a bunch of stuff in between the “” and maybe you only have a few things. A desktop system will probably have quite a few use flags listed here for multimedia codecs and such where a server may only have a very few. So we want to add in between the "" so the line looks like this:

Now we need to recompile anything on our system that may use that flag. This is a very simple command. As root type:

This will search your system and see if any packages that you have installed will make use of the new mysql use flag that was added to your /etc/make.conf file. If it finds any packages it will list the packages, and show mysql in red as a use flag indicating that it will be compiled into the package. Review the list and type yes to update the packages.

Note: by default the MySQL server is locked down to localhost access only. If you want to allow other connections to your MySQL server besides just the localhost then you need to edit /etc/mysql/my.cnf and comment out the following line by inserting a # in front of it:

Then restart the MySQL service by typing:

Your MySQL installation is now complete. A nice GUI application for managing your MySQL databases is mysql-workbench. You can install it on a Gentoo system with X installed by typing: