Setting Up Database Driven Websites - Installing MySQL (
Page 3 of 8 )
Okay, we actually get to do something now! Assuming you've downloaded
everything into /tmp, do this to install MySQL.
The MySQL file you downloaded will be called something like
mysql-3.22.21-pc-linux-gnu-i686.tar.gz, depending on your
platform.. Extract this into /usr/local, you must do this as root:
$ cd /usr/local
$ su
# gzip -dc mysql-3.22.21-pc-linux-gnu.i686.tar.gz | tar -xvf
After it extracts everything, a directory called
mysql-3.22.21-pc-linux-gnu-i686 (or similar) will be created.
We make a symlink to this directory and give it a friendlier name:
# ln -s mysql-3.22.21-pc-linux-gnu-i686 mysql
Next time there is a new version of MySQL, you can just extract the binary
distribution to a new directory and change the symlink.
Now we will create a user account to run the MySQL server daemons and to own
all the MySQL files. Add a new user called mysql on your system
using whatever commands are available for your OS (eg. useradd). No one should
be logging into this account, so disable logins by:
- setting the account expiry to a date in the past
- entering NP or * in the password field of /etc/passwd or
/etc/shadow
- whatever your OS recommends
Preparing MySQL
First let's change the ownership of MySQL directories and files to be owned
by the mysql user and the root group:
# cd /usr/local
# chown -R mysql mysql-3.22.22-pc-linux-gnu-i686 mysql
# chgrp -R root mysql-3.22.22-pc-linux-gnu-i686 mysql
Now we have to run a little script that creates the initial MySQL database,
do this a the mysql user. This is the only time we use this
account directly:
# su mysql
$ cd mysql
$ scripts/mysql_install_db
$ exit
If that didn't give you any error messages, you're well on your
way.
Make MySQL Start Automatically
MySQL comes with a little startup script in
/usr/local/mysql/support-files called
mysql.server. Make sure it is executable:
$ chmod +x /usr/local/mysql/support-files/mysql.server
You should call this from one of your system startup scripts. As this is
different for every operating system, refer to your system manual for more
information on how to do this.
Testing MySQL
MySQL comes with a sample database called test and its internal database that
keeps track of permissions and users, so let's fire it up and see if everything
is working so far. First start up MySQL:
# /usr/local/mysql/support-files/mysql.server start
If that worked, you should be able to something like:
Starting mysqld daemon with databases from /usr/local/mysql/var
The MySQL programs files are located in
/usr/local/mysql/bin, you may want to this to your path. Start the
client by running:
# mysql
You should see the following:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 3.22.22
Type 'help' for help.
mysql>
Next, list the installed databases by typing show
databases:
mysql> show databases;
You should see:
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)
If you did, then it's working!! Exit MySQL by typing exit:
mysql> exit;
Bye
Changing the Admin Password
The first thing to do after everything works is to change the administrator
password. Do this by running mysqladmin (remember that it may
not be in your path):
# mysqladmin -u root password newpassword
This sets the password for the user root to
newpassword. You probably don't want to use that, so substitute
it with something clever.