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

emerge -av mysql

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.)

ebuild /var/db/pkg/dev-db/mysql-*/mysql-*.ebuild config

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:

/etc/init.d/mysql start

Then set it to the default runlevel by typing:

rc-update add mysql default

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

mysql -u root -p

(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:
    use mysql;
  • View the MySQL database’s existing tables:
    show tables;
  • List the users:
    select * from user;

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:

  • nano -w /etc/make.conf
  • 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:
    USE= "..."
  • 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:

    USE="... mysql"

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

emerge -av --newuse world

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:

#bind-address                           =

Then restart the MySQL service by typing:

/etc/init.d/mysql restart

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:

emerge -avq mysql-workbench