MySQL is a popular, free software relational database management system. It is often used in conjunction with web applications (such as many PHP sites), but has gained many more enterprise-level features since its start in 1994.
An alternative fork and drop-in replacement is MariaDB.
Before installing, carefully consider the USE flags that influence the package deployment and features. The following table gives an overview of the package's supported USE flags:
USE flags for dev-db/mysql A fast, multi-threaded, multi-user SQL database server
|Add CJK support for InnoDB fulltext search using app-text/mecab
|Support for cracklib strong password checking
|Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
|Use dev-libs/jemalloc for memory management
|Use LATIN1 encoding instead of UTF8
|Enable NUMA support using sys-process/numactl (NUMA kernel support is also required)
|Add optional support/bindings for the Perl language
|Add support for statement profiling (requires USE=community).
|Build the MySQL router program
|!!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
|Build the server program
|Use the dev-util/google-perftools libraries to replace the malloc() implementation with a possibly faster one
|Install upstream testsuites for end use.
Once the proper USE flags have been set, install MySQL:
emerge --ask dev-db/mysql
- /root/.my.cnf - Potentially stores the root database user's password.
- ~/.mysql_history - Each user's SQL history. Note: Unless disabled, history is recorded here. This includes passwords in plain text.
- /var/lib/mysql - MySQL's default data directory. This can be adjusted in the 50-distro-client.cnf file above. Databases will be stored here.
To have the database(s) started automatically at boot, add the mysql init script to the default runlevel:
rc-update add mysql default
After configuring the database, which is mentioned later in this document, start the mysql service:
rc-service mysql start
emerge --config dev-db/mysql
This will create a database, set proper permissions on the database, and assist in creating a good root password (this is for the MySQL root account, which is not related to the Linux root account).
To purge anonymous users and test databases from the installation, run mysql_secure_installation after the preliminary setup:
When the database is up and running, connect to it using the mysql client application.
mysql -u root -p -h localhost
Enter root password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 5.5.1 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
From this point, a session to the MySQL instance is open, allowing for queries and administrative commands to be serviced.
Erasing command history
By default MySQL logs every action, including leaving plain text passwords in its history file.
To remove the history file:
Alternatively, history logging can be permanently disabled with the following:
ln -sf /dev/null /root/.mysql_history
Removing an old database
By default, the /var/lib/mysql directory is used as the SQL data directory; once databases have been created, they will be stored here. To remove old databases and start fresh, this directory can be renamed or removed so that a new database can be created.
mv /var/lib/mysql /var/lib/mysql.bak
chown mysql:mysql /var/lib/mysql