Install MySQL from Source
This is a HOWTO for installing MySQL on an x86-based Sun Cobalt RaQ or Qube server. MySQL is not used by the UI on any of these products, so replacing or installing it is not a big deal.
NOTE: This HOWTO is NOT for use on the MIPS-based products (Qube 2700, Qube 2, RaQ 1, RaQ 2). They need a compiler upgrade and some other stuff before you can build MySQL on them.
I designed this HOWTO so that you can just copy/paste each block of commands into your shell session and it will "just work" for you, thus avoiding typing (and typos) on your part.
If you cut-and-paste these steps EXACTLY on a "stock" server, the procedure WILL work properly! Dozens of other people have followed these exact steps with no problem. If you have a problem, it's something you did. If you try typing the commands yourself instead of cut-and-paste, you run the risk of a typo, a missed step, etc.
NOTE: If the MySQL version number has changed, please substitute the most up-to-date stable version of MySQL for whatever is specified here.
I have tested this procedure with both the 3.23.x and 4.0.x products. Both work fine. These directions assume you're installing the latest 3.23.x version. If you are installing 4.0.x, change the version numbers in each step accordingly.
ESTABLISH SHELL SESSION AS root
Use telnet or SSH to establish a shell session on the server.
REMOVE ANY OLDER VERSION OF MySQL
On a Qube 3, RaQ XTR, or RaQ 550 we need to remove the pre-installed version of MySQL first. It is installed via RPM, so just do:
rpm -qa | grep -i mysql
to get a list of all installed MySQL RPMs.
DANGER: IF YOUR MYSQL DATABASE ALREADY HAS CONTENT IN IT, THE NEXT STEP WILL ERASE THAT DATA!
To actually uninstall MySQL do:
rpm -e mysql-filename.rpm
for each RPM file listed by the rpm -qa step above.
GET SOURCE CODE FOR MySQL
Make a "working" directory
mkdir -p /home/src cd /home/src
Use the command-line browser lynx to visit www.mysql.com. Navigate to the Developer section, then Downloads, then select a mirror near you, and get the source code bundle for the latest MySQL version (source code is all the way at the bottom of the page).
Alternatively, if you know a direct mirror and version, you can use wget on the Cobalt server to pull the one file across:
Then "unpack" the source code:
tar zxf mysql-3.23.58.tar.gz
This will leave you with a directory structure like this:
BUILD AND INSTALL MySQL
First, we create the group and user that "owns" MySQL. For security purposes, we don't want MySQL running as root. To be able to easily identify MySQL processes in top or ps, we'll make a user and group named mysql:
groupadd mysql useradd -g mysql -c "MySQL Server" -d /dev/null -s /sbin/nologin mysql
Now we'll change to the "working" directory where the source code is, change the file 'ownership' for the source tree (this prevents build issues in reported in some cases where the packager's username was included on the source and you aren't using the exact same name to compile with!) and start building.
The configure command has many options you can specify. I have listed some fairly common ones; if you'd like to see others, do:
./configure --help | less
to see them all. Read the documentation on the MySQL website for a more detailed explanation of each option.
cd /home/src chown -R root.root mysql-3.23.58 cd mysql-3.23.58
CFLAGS="-O3" \ CXX=gcc \ CXXFLAGS="-O3 \ -felide-constructors \ -fno-exceptions \ -fno-rtti" \ ./configure \ --enable-assembler \ --with-mysqld-ldflags=-all-static \ --prefix=/home/mysql \ --localstatedir=/home/mysql/data \ --disable-maintainer-mode \ --with-mysqld-user=mysql \ --with-unix-socket-path=/tmp/mysql.sock \ --without-comment \ --without-debug \ --without-bench
Now comes the long part, where the source code is actually compiled and then installed. Plan to get some coffee or take a break while this step runs. It could be 10-15 minutes or more, depending on your system's free memory, load average, etc.
make && make install
CONFIGURE AND START MySQL
MySQL is "installed" but we have a few more steps until it's actually "done" and ready to start. First run the script which actually sets up MySQL's internal database (named, oddly enough, mysql).
Then we want to set the proper ownership for the MySQL directories and data files, so that only the mysql user (and root of course) can do anything with them.
chown -R root:mysql /home/mysql chown -R mysql:mysql /home/mysql/data
Copy the default configuration file for the expected size of the database (small, medium, large, huge)
cp support-files/my-medium.cnf /etc/my.cnf chown root:sys /etc/my.cnf chmod 644 /etc/my.cnf
If you get an error message about the data directory not existing, etc., something went wrong in the mysql_install_db step above. Go back and review that; make sure you didn't get some sort of error message when you ran it, etc.
Now we have to tell the system where to find some of the dynamic libraries that MySQL will need to run. We use dynamic libraries instead of static to keep the memory usage of the MySQL program itself to a minimum.
echo "/home/mysql/lib/mysql" >> /etc/ld.so.conf ldconfig
Now we want to set up a startup script, which enables MySQL auto-start each time your server is restarted.
cp ./support-files/mysql.server /etc/rc.d/init.d/mysql chmod +x /etc/rc.d/init.d/mysql /sbin/chkconfig --level 3 mysql on
Then we set up symbolic links for all the MySQL binaries, so they can be run from anyplace without having to include/specify long paths, etc. The links are created in /usr/local/bin/ (as opposed to /usr/bin or any other location) in accordance with the [Filesystem Hierarchy Standard].
cd /home/mysql/bin for file in *; do ln -s /home/mysql/bin/$file /usr/local/bin/$file; done
First, we will assume that only applications on the same server will be allowed to access the database (i.e., not a program running on a physically separate server). So we'll tell MySQL not to even listen on port 3306 for TCP connections like it does by default. Edit /etc/my.cnf and add
to the [mysqld] section.
For more security info, there is a great tutorial over at http://www.securityfocus.com/. The chrooting part won't be too relevant, but all the other info is good to know.
cd ~ /etc/rc.d/rc3.d/S90mysql start
Let's "test" it to see what version we're running now:
Now we'll set a new password for the MySQL root user (not the same as the system root user!)
mysqladmin -u root password new-password
(obviously, insert your own password instead of the "new-password" string!)
You're done! MySQL is now installed and running on your server. It is highly recommended that you read about MySQL security and lock down your server as much as possible. The MySQL site has info at http://www.mysql.com/doc/en/Privilege_system.html.
TEST THE MySQL SERVER
To run a quick test, use the command line program mysql:
mysql -u root -p
and enter your new root user password when prompted. You will then see the MySQL prompt:
First, while we're in here, we'll take care of another security issue and delete the sample database test and all default accounts except for the MySQL root user:
mysql> drop database test; mysql> use mysql; mysql> delete from db; mysql> delete from user where not (host="localhost" and user="root"); mysql> flush privileges;
Change the MySQL administrator account name from root to something harder to guess.
mysql> update user set user="sqladmin" where user="root"; mysql> flush privileges;
From now on, you will use the username sqladmin as the MySQL administrator name, not root!
Now, on with the "standard" testing... First, create a new database:
mysql> create database foo;
You should see the result:
Query OK, 1 row affected (0.04 sec)
Delete the database:
mysql> drop database foo;
You should see the result:
Query OK, 0 rows affected (0.06 sec)
To exit from MySQL enter \q:
mysql> \q Bye
MySQL TEST SECTION TO BE FINISHED LATER...