MySQL 5.5.11 Tutorial - Step Two April 27, 2011 April 21, 2011 Jonathon Byrd Spelling, Grammar, Punctuation, and Format Fixes for Text by CW Cyrix Original link http://www.5twentystudios.com/blog/2011/04/21/installing-mysql-5-5-11-tutorial- step-two/ If you haven’t backed up your system yet, then head back to step one: Backing up MySQL Alright, this second step assumes that you have a server thats not running MySQL. I’m using Ubuntu 9.04 (Jaunty Jackalope) and installing MySQL 5.5.11. If you run into any problems, go ahead and post the problem in the comments along with any solution that you find. I apologize but I probably willn’t be able to provide support to help you with all of the problems that you guys will most likely run into. Download the binary For the purposes of this tutorial I’ll be using the latest MySQL version, 5.5.11. I was able to finally locate the proper installation package from this helpful directory: SoftAgency.net. FYI, this download from server to server took me about thirty minutes. $ cd /tmp/ $ chmod -R 777 . $ wget http://download.softagency.net/MySQL/Downloads/MySQL-5.5/mysql-5.5.11- linux2.6-i686.tar.gz Install the asynchronous I/O library This is so that we can take advantage of the asynchronous I/O capability in the new InnoDB plugin that ships with MySQL 5.5 $ apt-get install libaio-dev Untar the archive $ tar xzvf mysql-5.5.11-linux2.6-i686.tar.gz Add the path to MySQL bin directory to the PATH variable Your environment file may look different than this. The point here is to add the /usr/local/mysql/bin to the paths. $ vim /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: /usr/local/mysql/bin" $ source /etc/environment Making sure that we have the proper users and groups You can skip this step if you had MySQL previously installed on your system. $ groupadd mysql $ useradd -r -g mysql mysql Create the socket directory Here again, setting the correct permissions on the socket directory is very important, otherwise MySQL would not run. $ mkdir /var/run/mysqld/ $ chown -R mysql:mysql /var/run/mysqld/ Copy or move the untarred MySQL directory to the installation directory It would make sense to do this prior to setting the environment paths, however, this is the point at which I find myself restarting this process over and over again until I get it right. $ cp -R mysql-5.5.11-linux2.6-i686 /usr/local/ $ cd /usr/local/ $ ln -s mysql-5.5.11-linux2.6-i686 mysql Consider this Checkpoint One. Set the correct file and directory permissions on the MySQL installation directory Setting correct permissions is very important, and setting them in the proper order is even more important. The first step is to set everything to mysql for the installation and then we’ll set them back to root for security reasons. Make certain that you’re in the /usr/local/mysql directory or you’re going to cause some major issues. $ cd / $ chown -R mysql:mysql /usr/local/mysql $ chown -R mysql:mysql /var/lib/mysql $ chown -R mysql:mysql /var/run/mysql $ chown -R mysql:mysql /var/run/mysqld Copy the sample MySQL configuration file to the etc directory and setup the paths I actually had to look inside my support-files directory and see what .cnf files were available to me. Depending on what you downloaded, yours may differ from my-huge.cnf. $ cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf Now edit /etc/my.cnf so that it has the following values: [client] user = mysql socket = /var/run/mysql/mysql.sock port = 3306 [mysql.server] user = mysql basedir = /var/lib/mysql/mysql [safe_mysqld] err-log = /var/log/mysql/mysqld.log [mysqld] user = mysql socket = /var/run/mysqld/mysqld.sock port = 3306 pid-file = /var/run/mysqld/mysqld.pid basedir = /usr/local/mysql #/path/to/datadir/mysql datadir = /var/lib/mysql/mysql tmpdir = /tmp log_error = /var/log/mysql/error.log #You need to update this to your servers IP address bind-address = 0.0.0.0 Run the Installation Script The official installation guide suggests that you run this command prior to moving or adjusting the my.cnf file, however, I’ve found it more beneficial to use the my.cnf file as the defaults when running this installation script. $ cd /usr/local/mysql $ /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql Copy the MySQL server startup script to the startup directory The MySQL startup script has to be placed in the directory where all the startup scripts reside, so that MySQL starts on system startup. Make sure that you make the startup script executable, and update the rc.d database to notify the system about the presence of a new startup script. $ cd /usr/local/mysql/support-files/ $ cp mysql.server /etc/init.d/mysql $ chmod +x /etc/init.d/mysql $ update-rc.d mysql defaults I ran into a lot of problems with mysqld not being installed as well, so I peered inside my support-files directory again and located the mysqld server file and repeated these steps. $ cp mysqld_multi.server /etc/init.d/mysqld $ chmod +x /etc/init.d/mysqld $ update-rc.d mysqld defaults Starting MySQL in safe mode When starting the MySQL server for the first time after the new installation, it has to be started without the grants table, for two reasons. Firstly, because we want to retain the users and privileges data from the previous install of MySQL and secondly, because the schema of the grants table in MySQL 5.5 has changed. So what we will do is start MySQL without the grants table, import the users and privileges data we backed up earlier in this guide and run the mysql_upgrade script that modifies the schema of the grants table to be in sync with that in MySQL 5.5. After that we will be able to run MySQL normally and have all the users and privileges same as in the previous version we had. $ /usr/local/mysql/bin/mysqld_safe --user=mysql Let’s check to see if we can call mysql If you’re system throws any errors, well then, something went wrong and you need to start over from the last checkpoint. Otherwise, PHEW *wipe your brow* and proceed with the restoration of your backups. $ mysql If starting MySQL failed, have no fear, a lot of people are having the same problems that you’re having. Your next step is to open step three along side step two and work yourself through this process, Step Three – Debugging. Consider this Checkpoint Two. Loading your backups Navigate to your backup directory and run the sql dump file. I actually ran into a problem at this step and had to finish configuring the security/ passwords before I could finish restoring my old databases. Have a look here: Setting MySQL Passwords and Security. $ cd /root/mysql-5.1-dump $ mysql < mysql.sql Run the upgrade script so that everything gets upgraded to the version 5.5 $ mysql_upgrade Stop the server and start it normally $ /etc/init.d/mysql stop $ /etc/init.d/mysql start There you go, you have a MySQL 5.5 server up and running in no time! Do share your problems and your fixes with the rest of us. For those of you that are moving on to the next phase, I suggest that you head to the next step of setting up your passwords and securing your MySQL server installation: MySQL Security.