|
Home » Articles » Databases »
DBI, Part 3: How to install and configure MySQL
Dateline: 12/19/99
This is Part Three in a four part series on using DBI. In DBI, Part 1: Databases and drivers we learned about installing the correct database drivers. In DBI, Part2: How to program with databases, I showed you the basic information you'll need to know to use DBI. This week I'll show you how to install and configure MySQL.
Introduction
In the earlier parts of this series I have given you a lot of general information about DBI. Now I'll show you how to put it into action, using MySQL as an example. Although the example will be on a Linux system, I'll try to keep things as operating system independent as I can.
Downloading MySQL
The first thing you'll need to do is download MySQL. Although there are a lot of options available, you'll need to start with the latest version of the precompiled binaries for your operating system. The version numbers among the different operating systems are similar, although they may not match exactly. In this example, I'll be downloading to a directory called /tmp. The downloaded file has a name something like mysql-3.22.27-pc-linux-gnu-i686.tar.gz, depending on your operating system and the version you downloaded.
Installing MySQL
Now that the file is downloaded, you'll have to extract it into the working directory. If you have root access, you'll want to use something like /usr/local. If you don't have root privileges, you'll need to talk to your network administrator to find out what directory to use.
1. Change to the correct directory
$cd /usr/local
2. You'll need root privileges to continue the installation
$ su
3. Extract the files
# gzip -dc /tmp/mysql-3.22.27-pc-linux-gnu-i686.tar.gz | tar -xvf
Create a symlink
To make things easier, create a symlink to the new directory. This will not only make it more friendly, it will make it easier when you update, since all you'll need to do is change the symlink to the new directory created when you install the update. # ln -s mysql-3.22.27-pc-linux-gnu-i686 mysql
----------------------------------------------------------------------------
Create a new MySQL user account
OK, now we need to create a user account so that you can change the ownership of all the mySQL files, and to run the mySQL server daemon. Add a user as you normally would for your operating system. Because nobody should ever be logging into this account, you should disable logins by following the recommended procedure for your operating system.
Now that you have created a new account, its time to change the ownership of the files and directories to the new mysql user and the root group.
$ su
# cd /usr/local
# chown -R mysql mysql-3.22.27-pc-linux-gnu-i686 mysql
# chgrp -R root mysql-3.22.27-pc-linux-gnu-i686 mysql
Create the initial MySQL database
The initial MySQL database consists of a sample database named 'test', and the internal database it uses to keep track of users and their permissions. To create it, you'll need to log in as the new mysql user for the first and only time.
# su mysql
$ cd mysql
$ scripts/mysql_install_db
$ exit
Starting MySQL
To start MySQL, type # /usr/local/mysql/support-files/mysql.server start
When it starts you should see something similar to
Starting mysqld daemon with databases from /usr/local/mysql/data
If you want to start MySQL automatically, be sure to make the startup script executable,
# chmod +x /usr/local/mysql/support-files/mysql.server
and then add it to the system startup script for your operating system. You'll need to check the documentation for instruction on how to do this.
----------------------------------------------------------------------------------
Testing MySQL
Now its time to start the MySQL client. The files you'll need are located in /usr/local/mysql/bin, and you'll want to add this to your path. Let's get started.
# mysql (or /usr/local/mysql/bin/mysql)
You'll see something like
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection is 1 to server version: 3.22.27
Type 'help' for help.
mysql>
Now let's make sure that the initial MySQL database shows up correctly. Type
mysql> show databases;
You should see:
+-------+
| Database |
+-------+
| mysql |
| test |
+-------+
|