Search:  
Gentoo Wiki

MySQL/Install


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

This HOWTO should allow you to get up and running a basic MySQL installation

Contents

Getting Started

Unless you have a particular need for an older version of mysql such as 3.23.58-r1 or 4.0.25-r2 (in which case you probably know exactly why you need it and don't need this HOWTO), you shouldn't include berkdb in your USE flags. As of 5.0.26-r2 'Berkeley DB support is deprecated and will be removed in future versions', so berkdb is probably not something you should run with for new installations.


Installing MySQL 5.0.54 and 5.0.60-r1 was failing for me due to berkdb flag - after removing the flag emerge passed. As berkdb is not set in make.conf, package.use nor profile/make.defaults - I'm not sure where it is getting it from, but adding 'dev-db/mysql -berkdb' to /etc/portage/packages.use worked.



If you are trying to install a version of MYSQL older than 4.1, you might want to add innodb to the USEflags.

It is *strongly* recommended that you use the /etc/portage/package.* files instead of USE=" " on the command line if you want to enable a USEflag for one package. The biggest benefit of this is that on future upgrades of the package, your same use flags will be applied.

To add custom use flags to a package, first create the /etc/portage directory. It does not exist by default. Next, create a package.use file. The format of this file is very simple, do not add the version number to the packagename.

package-category/packagename {useflags}

File: MySQL package.use file entry
dev-db/mysql innodb berkdb another-use-flag 

What this entry means is "I want all versions of MySQL to be emerged with InnoDB, berkdb and another-use-flag support".

List MySQL, its dependencies, and the USE flags they take. If you missed a USE flag, you can always edit your package.use and add it

# emerge dev-db/mysql -pv

Install MySQL, and any dependencies it may have.

# emerge dev-db/mysql

Auto-Updaters

If you automatically run updates on your machine (through a cron script for instance) you may wish to emerge mysql 'once.'

# emerge -1 dev-db/mysql

This will emerge the dev-db/mysql ebuild without adding it to the world namespace. Thus, whenever you type 'emerge --update world' mysql will not be updated. This is extremely useful since portage doesn't support straight, unattended updates for mysql. Since you will have to manually update mysql anyway, you may wish to remove it from world so that your auto-update script(s) don't fail.

Note that doing this will mean that emerge --depclean may remove mysql, since it is not in world, and may not have any packages in world that do depend on it.

Creating the Databases

As asked by the mysql ebuild please run this to create the initial mysql databases

emerge --config =dev-db/mysql-4.1.21 

Replace '4.1.21' with the version of MySQL that you have installed. Tab completion is your friend ;)

To get the version number: I recommend looking at for your current install

emerge -pv mysql

Note: If you only have one version of MySQL installed, emerge is able to implicitly find the correct program version number, thus only package name is needed

 emerge --config dev-db/mysql

Complete any directions output by the config.

Starting MySQL

Start MySQL

/etc/init.d/mysql start

To add MySQL load at boot add it to the default runlevel.

rc-update add mysql default

To set security.

mysql_setpermission

(The "mysql_setpermission" script requires DBI and DBD-mysql to be installed. This is not called out in the install instructions/dependencies above.)

You have to use the password you set for the root user when you ran emerge --config as above.

An alternative method is to set the user permission in the mysql client by using the command "SET PASSWORD FOR <username>@<hostname>=<password>"

eg.

mysql> SET PASSWORD FOR 'root'@'localhost'=PASSWORD('betchawontguessit');

The method shown here, using PASSWORD('') will encrypt the password, whereas it will otherwise be entered in plain text (NOT recommended).

Adding security

You should also run mysql_secure_installation to secure mysql. Like disabling anonymous, setting security options and set root password.

mysql_secure_installation 

You can also add a regular user for daily use.

mysql_setpermission

Testing

To test your install login to mysql and provide your admin password.

$ mysql -u root --password

you should receive a mysql prompt

mysql>

type in the following command to see if the databases were created properly

mysql>show databases;

and if you receive a list of databases you're all set

See Also

Apache2 Index - For setting up a LAMP Machine

Common Problems

Q: What if you cannot login to MySQL after your installation?

$ mysql -u root -p

A: Try 'mysql' as default password.

OR

As root.

$ /etc/init.d/mysql stop
$ mysqld_safe --user=mysql --skip-grant-tables --skip-networking && mysqladmin -u root flush-privileges password 'newpassword'
$ /etc/init.d/mysql start
 

OR

If the above does not work, try:

$ /etc/init.d/mysql stop
$ mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
$ mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit;

Then kill the mysqld_safe, and restart mysql.

Q: When I run /etc/init.d/mysql start, it says mysql started successfully, but it's not working and not showing up on the process list when I run ps -A! What do I do?

A: Make sure the mysql user can write to the /tmp directory. If you're running a more secure system, you may have restricted write access to /tmp without realising it (this is a good practice, however). To avoid this problem, it is suggested that you change the group for /tmp to users and allow the group to write to it, then add mysql to the users group.

As root:

$ chgrp users /tmp
$ chmod 0664 /tmp
$ gpasswd -a mysql users

Finally, restart the mySQL server (remember to zap it because while it's 'running' it's not actually running, Gentoo just thinks it is).

$ /etc/init.d/mysql zap
$ /etc/init.d/mysql start

Q: When your run /etc/init.d/mysql start for the first time, it claims that it can not find /etc/mysql/my.conf and appears to be getting slotting off.

A: You might not have any version of mysql selected as the default, try this as root: NOTE: This does not work with newer versions of MySQL as eselect-mysql only works with slotted versions. A better solution is required.

$ eselect mysql set $version      (5.0.x for me currently)
$ /etc/init.d/mysql start

Q: What if you cannot connect to the server from a remote client?

A: Make sure you have networking enabled and your server isn't listening to the loopback interface. To do this comment the following lines from /etc/mysql/my.cnf:

#skip-networking
#bind-address                   = 127.0.0.1

Note: if you want to bind the server to a specific interface, replace 127.0.0.1 with the address of that interface.

See Also

Retrieved from "http://www.gentoo-wiki.info/MySQL/Install"

Last modified: Sun, 10 Aug 2008 06:52:00 +0000 Hits: 82,600