Even though MySQL runs on many platforms, we will explain how to install it on Linux, Unix, Microsoft Windows, and Mac, which together account for the vast majority of websites on the Internet. Be sure to read the manual all the way through before starting the installation.
Installing MySQL on Windows Using Setup Wizard
To set up MySQL on Microsoft windows, follow these steps:
- Double-click the installer (.msi) file that you obtained from MySQL website. The opening screen shown below.
- Click Install MySQL Products. You will see a screen to accept the license agreement. After checking its terms and conditions, you must click agree to continue, select I Accept the License Terms and click Next.
- Select Execute. Updates will be downloaded. On the Choosing a Setup Type tab, select Full, as shown below.
- Click Next. A requirements check may be executed; if so, click Execute. The prerequisites will be installed, if necessary. Click Next as appropriate to install the prerequisites. The Installation Progress screen will be displayed.
- Click Execute. The installation progress will be displayed for each component and then the configuration part will begin.
- In the Configuration Overview dialog, simply click Next to begin the configuration procedure.
- Choose Developer Machine from the MySQL Server Configuration dialog and click Next.
- On the MySQL Server Configuration dialog, enter the password that you’ll use for root or administrator access and click Next.
- On the Configuration Overview dialog, click Next to install the samples.
- When the samples have been installed, click Next.
- On the Installation Complete dialog, click Finish.
Installing MySQL on Linux from an RPM file
You can install MySQL on Linux using RPM ( Red Hat Package Manager ). Although, prior to installing the RPM from MySQL you should see if your distribution has MySQL already packaged. Using the packaged version of MySQL is almost always preferable and is almost always easier to both install and maintain later.
To install MySQL on Linux from an RPM file provided on the MySQL website, follow these steps:
- Change to the directory where you saved the MySQL installer files. For instance, type cd /usr/src/mysql.
One file is named MySQL-server-, followed by the version number, followed by .i386.rpm. The next file has the same name with client, instead of server, in the name.
- Install the RPM by typing this command:
1rpm -i listofpackages
For example, the command might be
1rpm -i MySQL-server-5.0.35-0.i386.rpm MySQLclient- 5.0.35-0.i386.rpm
This command installs the MySQL bundles. It sets the MySQL group name and account that you need and creates the data directory at /var/ lib/mysql. It also starts the MySQL server and creates the appropriate entries in /etc/rc.d so that MySQL starts immediately each time your computer starts. You need to be using an account that has authorizations to successfully run the rpm command, such as a root admin account.
- To check that MySQL is operating well, input this command:
You should see the version number of your MySQL server.
Installing MySQL on Mac from a DMG file
You can install MySQL using a Mac OS X 10.2 (Jaguar) or later PKG binary package obtained from the MySQL website at www.mysql.com. If your operating system is earlier than OS X 10.2, you can not use this bundle; you will need to download a tarball (a file that is a container for many files and subdirectories) and install MySQL from source code, as described in the next section.
- Create a user and a group named mysql for MySQL to run under. In most latest Mac versions of OS X, this user and group already exist.
- Change to the directory where you downloaded MySQL — for instance, /usr/local. You see a package named mysql-, as well as the version number and the OS number and dmg, such as mysql- 5.0.37-osx10.4-powerpc. dmg. If the obtained file doesn’t have the extension .dmg, modify the filename to give it the .dmg extension.
- Attach the disk image by double-clicking its icon in the Finder.
- Double-click the package icon to set up the MySQL PKG. The package installer runs and installs the package. It installs MySQL in the directory /usr/local/mysql-, followed by the version number. It also installs a symbolic link, /usr/local/mysql/, pointing to the directory where MySQL is installed. It initializes the database by running the script mysql_install_db, which creates a MySQL account called root.
- If needed, change the owner of the mysql directory. The directory where MySQL is installed (for example, /usr/local/ mysql-5.0.37) should be owned by root admin. The data directory (such as /usr/local/mysql-5.0.37/data) must be owned by the account mysql. Both of the directories should belong to the group mysql. If the user and group aren’t correct, modify them with the following commands:
1sudo chown -R root /usr/local/mysql-5.0.37
1sudo chown -R mysql /usr/local/mysql-5.0.37/data
1sudo chown -R root /usr/local/mysql-5.0.37/bin
- Install the MySQL Startup Item. To have your MySQL server start every time the computer starts, you need to install the MySQL Startup Item, which is included in the installation disk image in a different installation package. To install the Startup Item, double-click the MySQLStartupItem.pkg icon.
Installing MySQL from source files
Before you decide to install MySQL from source files, check for RPMs or binary files for your operating system. MySQL RPMs and binary files are precompiled, ready-to-install packages for installing MySQL and are simple and reliable. You can set up MySQL by compiling the source files and installing the compiled packages. This process sounds complex and daunting, but it is not. However, read all the way through the following steps before you start the installation process. To install MySQL from source code, follow these steps:
- Create a user and group ID for MySQL to run under by using the following commands:
1useradd -g mysql mysql
The syntax for the commands might differ slightly on different versions of Unix, or they might be called addgroup and adduser.
Note: You must be using an account authorized to add users and groups.
Note: Some recent Linux distributions and Macs have a mysql account already provided.
- Change to the directory where you downloaded the source tarball — for instance, cd‑/usr/local. You see a file named mysql-, followed by the version number and .tar.gz — for example, mysql-5.0.35.tar.gz. This file is a tarball.
- Unload the tarball by typing
1gunzip -c filename | tar -xvf –
1gunzip -c mysql-5.0.35.tar.gz | tar -xvf –
You see a new directory named mysql-version — for instance, mysql‑5.0.35 — which contains many files and subdirectories. You must be using an account that is allowed to create files in /usr/local.
- Change to the new directory. For instance, you might type cd mysql-5.0.35.
- Type the following:
You see several lines of output. The output will tell you when configure has finished. This might take some time.
- Type make. You see many lines of output. The output will notify you when make has finished. make might run for quite a while.
- Type make install. On a Mac, type sudo make install. make install finishes quickly.
Note: You may really need to run this command as root.
- Type scripts/mysql_install_db. This command runs a script that initializes your MySQL databases.
- Ensure that the property and group membership of your MySQL directories are correct. Specify the ownership with these commands:
1chown -R root /usr/local/mysql
1chown -R mysql /usr/local/mysql/data
1chgrp -R mysql /usr/local/mysql
These commands make root the owner of all the MySQL directories except data and make mysql the owner of data. All MySQL directories belong to group mysql.
- Start the MySQL server using the following commands: On a Mac:
If essential, input your password. Press Ctrl+Z, and then type:
Finally, press Ctrl+D or type exit. On Linux/Unix:
1cd /usr/local/mysql bin/mysqld_safe --user=mysql &
- Set up your computer so that MySQL starts immediately when your device starts by copying the file mysql.server from /usr/local/ mysql/support-files to the location where your system has its startup files.