I've written before I prefer to do a manual install of MySQL over a repository one. I still do: I typically install from binary tarball or by compiling from source.
I'd like to share my setup procedure for Linux installation and service setup. I've done this dozens of times, on different Linux flavors, and it works well for me.
Installing from source
To get this straight: you sometimes have to compile the source files. I, for example, happen to use the Sphinx MySQLSE extension. You can only use it if compiled with MySQL. You had to compile a "vanilla" 5.1 version without query cache in order to completely remove the cache's mutex contention.
Anyway, I find the easiest way is to install onto a path associated with the server version. For example, I would install a 5.5 server onto /usr/local/mysql55
This way, a new version gets its own path, and no ambiguity.
To do that, use the prefix option on configuration step:
cd /path/to/extracted/source/tarball sh BUILD/autorun.sh ./configure --prefix=/usr/local/mysql55 make sudo make install
Once this is complete, you have everything under /usr/local/mysql55. This means binaries, libraries, scripts, etc.
To install the MySQL server as a service, copy the mysql.server script to /etc/init.d:
sudo cp /usr/local/mysql55/support-files/mysql.server /etc/init.d/mysql55
Again, I'm naming the script after the MySQL version. This avoids conflict with possible past or future installations of the MySQL server, which typically create a service named mysql or mysqld.
A thing to note about the mysql.server script is that it allows you (at around line #45) to set two variables:
- basedir: path to your installation directory. When compiling from source this is already setup with the path provided to the configure script. Thus, in our example, you can expect this variable to read /usr/local/mysql55. So basically nothing to do here.
- datadir: path to your data directory. If you're putting your my.cnf file in /etc or /etc/mysql, then setting datadir in my.cnf suffices. However, if you're going to put my.cnf itself on the data directory (e.g. so as to avoid collisions) then make sure to set the variable in the mysql.server init script.
Depending on your $PATH configuration, it is also a good idea to specify basedir variable on your my.cnf's [mysqld] section.
Which leads us to $PATH: your linux system is still unaware of the many binaries you've got in there. I typically add the following line at the end of /etc/bash.bashrc:
This is the most global PATH settings one can do. Alternatively, use /etc/profile, ~/.bashrc etc. (you may have noticed by now I'm working with bash).
Finally, need to setup the init script to run at startup and stop at shutdown.
- On Debian/Ubuntu/related I use rcconf (I'm too lazy to remember the command line setup).
- On RedHat/CentOS/related I use chkconfig --add mysql55, or linuxconf (since I'm lazy).
Installing from binary tarball
The only difference is that the mysql.server script is unaware of our deployment path. So the basedir variable must be set in that file. Other than that, follow same steps as for source installation (oh, of course no need to configure & make...).