MYSQL-TOOLS

Comparison of graphical tools for MySQL

Home Installing MYSQL

Installing MySQL

In this lesson of the MySQL tutorial, you will learn...
  1. To install MySQL on different Operating Systems.
  2. To use installation options.
  3. To configure and check the installation.
  4. To consider Non-traditional installation as in building Source Files.

Installing MySQL is considerably streamlined and usually straightforward when using defaults as shown below.

 



Installing MySQL

Print PDF
User Rating: / 1
PoorBest 

Installing MySQL

Gaining in popularity, MySQL Database Server now runs on a wide range of platforms. In this lesson we will focus on Linux, Unix, Windows, and Mac, which combined together account for the majority of installations.

MySQL is installed best from precompiled, ready-to-install binaries - packages. Binaries are available for most operating systems: Linux, Windows, Mac, FreeBSD and other flavors of Unix, and many more.

Operating System Selection

Programs such as Apache and MySQL are natively designed and better optimized for the programming model of Unix/Linux than for Windows, and this provides a significant performance advantage in favor of installing MySQL on Unix/Linux.

Generally, developers mostly prefer machines using MS-Windows OS variants. Nevertheless, if the production deployment is on a Unix/Linux server, it may be better to choose a Unix/Linux platform during the development phase itself. This will help developers acquire useful experience in scripting, access rights and security that will be valuable in later phases of deployment, administration and maintenance.

Certain system functions on Unix/Linux make programming more attractive than Windows. For example, unlike Windows, Unix/Linux provides out-of-the-box interfaces for such tasks as remote copying or sending an e-mail via scripts. Several packages, such as Cygwin and MKS, are available on Windows and offer a Unix-like environments, commands and shells to build reusable scripts for Unix.

Downloading and Installing MySQL On Windows

To download and install MySQL on Windows, please follow these steps:

  1. Go to the Downloads page on MySQL website.

    Install my sql

  2. On the next screen, download your desired installer executable from the MySQL Community Server and save it to a folder on your system. Install mysql site
  3. Open the downloaded zip file, and execute the installer (.msi) file. Proceed with the extraction. If you're installing from a Windows system, be sure that you're logged into an account with administrative privileges. Select a folder to extract the zip folder.

    Install mysql server

  4. The extraction process completes.

    how to Install mysql

  5. Extraction will show you the setup file in the folder where you saved it.

    Install Tools of MySQl

  6. Once the opening screen appears, click Next to see a screen for choosing the type of installation.

    MySQL Server 5.0 installing

  7. Choose Typical installation then click Next. This will install all the required components for working in My SQL. The Ready to Install Program window opens. The current settings are displayed.

    What's my sql?

  8. Set up is now ready to begin installing the selected components. Click Install. The installation of My SQL begins. When the installation is complete, a Sign-Up dialog box opens.

    Install programm mysql

  9. Click Skip Signup and then click Next. The Wizard Completes. MySQL is now installed on your machine.

    Install

Running the My SQL Configuration Wizard

You will need to perform some basic configuration for MySQL to work smoothly. For instance, you need to assign a password to the MySQL account, named root, which is installed automatically, and you may want to set it up so that MySQL automatically starts when your computer boots.

MySQL provides a configuration wizard, which starts immediately after installation if you select Configure the MySQL Server Now in the final installation screen. You can also start the configuration wizard at any time using a menu item in the MySQL Start Menu.

  1. Select Configure the My SQL Server Now option.

    Note: A minor upgrade may not require reconfiguration of the server, as the wizard will use the same configuration as the existing version.

  2. Click Finish.
  3. Choose Standard Configuration, which will allow MySQL to be manually tuned. Click Standard Configuration and then click Next. The Windows Options dialog box opens.

    MySQL configuration

  4. Select both options here.

    Select Install as a Windows Service.

    Warning: If you are using Windows 98/Me, installing as a Windows service is not possible. Instead, select Add bin Directory to Windows PATH and skip to Step 7.

    Give a name to the service in the Service Name bo x, typically set to "My SQL" if you have only one install.

    Select Launch the MySQL Server Automatically.

    Select Add Bin Directory in Windows PATH.

    Install MySQL as windows services
  5. Click Next. The security options dialog box opens. Select Modify Security Settings.

    In the New Root Password box, type a password. In the Confirm box, retype the same password.

    Warning: You are now setting the password for the root account for your MySQL server. You must use the root account to access your MySQL databases, so you need to remember the password!

    If you are setting up a development environment that no one can access but you, you can select Create an Anonymous Account. An anonymous account is handy; however, if there is any access to your MySQL server from the Internet, do not create an anonymous account. We will discuss security risks later.

    Security MySQL
  6. Click Next. The Ready to Execute window opens. Select Execute to start configuring your MySQL server instance.

    Mysql server configuration

  7. A message appears when the configuration is complete.

    Install mysql tools

Note: If you have more than one version of MySQL installed, a screen appears and you can click the version you want to configure. Then, click Next. The MySQL Server Configuration Types window opens.

Starting and Stopping the My SQL Server

In most cases, when you download and install My SQL, the server is started automatically. You can set up MySQL so that it automatically starts every time your computer starts.

You may sometimes require to stop or start the server manually. For instance, if you reconfigure MySQL options, you may need to shut down the server before options apply.

If you have trouble starting the MySQL server after installing it, check the error log for useful information. The error log, which will be discussed in a future lesson, is located in the data directory and has the extension .err.

On Windows OS

To stop or start the MySQL server, do the following:

  1. Open up Services under Windows. A list of all current services appears.
  2. Scroll down the alphabetical listing, and click the MySQL service you want to stop or start. Stop or Start links appear to the left of the service name.
  3. Choose Stop or Start from the menu or links.

Note: If MySQL server is not set up as a service and is not in the list, we can set it up as a service using the configuration wizard.

Starting Manually (Not a Windows Service)

If setting up MySQL as an automatically running service is not an option, you can start the server manually as follows:

  1. Open a (DOS) Command Prompt window.
  2. Change to the bin directory in the directory where MySQL is installed. Your installation will likely be in c:\Program Files\MySQL\MySQL Server 5.0\bin.
  3. Issue a startup:

    Code Sample:

    mysqld
    REM mysqld-nt
    Code Explanation

    If this command fails, type mysqld-nt. Which program name you type depends on the MySQL version.

    Note: If the server starts, no message is displayed. You must leave this window open while the server is running. If you close the window, the server will shut down, although it sometimes does not shut down immediately. An error message is displayed if the server is unable to start.

Manual Shutdown

You can shut the server down manually as follows:

  1. Open a Command Prompt window and change to the MySQL bin directory.
  2. Issue a shutdown:

    Code Sample:

    mysqladmin -u root -p shutdown
    Code Explanation

    We are using the root account. The -p will prompt you to type a password. If the root account does not require a password, leave out the -p.

Installing MySQL On Linux and Unix

Linux machines may come with MySQL already installed. Many Linux systems, such as Fedora, SuSE, and Ubuntu, include built-in utilities that download and install MySQL, generally the latest version. It may be easier and efficient to install MySQL provided by the Linux distribution than the option of downloading and installing MySQL from the MySQL Web site.

Check your Linux distribution's web site to check if they offer an easy way to install MySQL.

For Unix, you can install from a binary file specific to your operating system. The binary files are adapted for the specific installation mechanims of the operating system. As of this writing, MySQL binary files are available for Solaris, HP-UX, AIX, SCO, SGI Irix, OpenBSD, FreeBSD, and other Unix flavors.

Using RPM (Linux only)

On a Linux computer, you can install My SQL using RPM files that you download from the MySQL web site (or it may already be on your Linux installation CD). Using RPM is the easiest way to install on Linux. Although RPM stands for Red Hat Package Manager, RPM is available on most flavors of Linux.

To install MySQL on Linux from an RPM file provided on the MySQL web site, follow these steps:

  1. Download the appropriate version of MySQL 5.0 server for Linux. You need to download both the server RPM and the client RPM.
  2. Change to the directory where you saved the downloads. You see two files in the directory:
    1. MySQL-server-, followed by the version number and .i386.rpm, and
    2. A second file named similarly with client in its name. For example, MySQL-server-5.0.27-0.i386.rpm and MySQL-client-5.0.27-0.i386.rpm.
  3. You may verify the downloaded files. See the Verifying a Downloaded File section later in this lesson.
  4. Install the RPM by entering this command:

    Code Sample:

    rpm -i listofpackages
    rpm -i MySQL-server-5.0.27-0.i386.rpm MySQL-client-5.0.27-0.i386.rpm

    This command installs the MySQL packages. It sets the MySQL account and group name 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 automatically whenever your computer starts.

The rpm utility allows you to work with RPM package files. The -i switch indicates that you want to install the specified package. Executing this command typically causes the following events:

  • The MySQL user account and MySQL group account are created in Linux.
  • The MySQL files are extracted from the RPM package and copied to their appropriate directories.
  • The MySQL administrative database initializes.
  • Ownership of MySQL-related directories and files is altered.
  • The MySQL server starts.
  • The MySQL server is set up to start automatically when you start up Linux.

The RPM extraction process provides output in the command window as it executes.

My SQL Packaged RPMs

The table below provides a list of usual RPM packages for Linux.

Package Name Contents
MySQL-server-n.rpm Contains the MySQL server.
MySQL-client-n.rpm Contains client programs (mysql, mysqladmin, etc.).
MySQL-shared-n.rpm Contains the shared libraries used by many programs to access MySQL.
MySQL-devel-n.rpm Contains libraries and include files for program development in C.
MySQL-embedded-n.rpm Contains a special version of the MySQL server that can be integrated into other programs (for C developers only).
MySQL-bench-n.rpm Contains scripts with benchmark tests.
MySQL-Max-n.rpm Contains the Max version of the MySQL server, which contains some supplementary table formats and experimental functions.

Using a Tar File to Install MySQL

You can use a tar file to install MySQL. The process though is not nearly as simple as it is with the RPM approach. You may need this on a version of Linux that doesn't support RPM installations or in situations where you want to have more control over the installation process.

To use a tar file to install MySQL, you need to follow specific steps as shown:

  1. Create a login account and a group account.
  2. Copy the tar files to your computer.
  3. Unpack the distribution file.
  4. Initialize the installation and set permissions.
  5. Configure the MySQL server startup options.
  6. Set up automatic start if desired.
  7. Start the MySQL server.

Starting the Server Automatically

Although it's useful to know how to start and stop the MySQL server manually, in most cases you want the server to start automatically when you start up Linux. To do this, you must copy the MySQL.server script to the proper directory, which, in this case, is /etc/init.d. The MySQL.server script, located in /usr/local/MySQL/support-files, provides the necessary commands to start MySQL automatically.

To set up the MySQL server to start automatically, you must take the following steps:

  1. First, copy the MySQL.server script to the init directory with name MySQL:

    Code Sample:

    mysqladmin --version
    Code Explanation

    The cp command copies the My SQL-server script to the /etc/init.d directory. The copied script is named MySQL.

    We also make the My SQL script executable using chmod and +x switch.

  2. You must next activate the script. In Linux, use the following command:

    chkconfig --add MySQL

    The chkconfig utility allows you to maintain configuration information. By using the utility with the --add MySQL option, you're ensuring that the MySQL service has a start entry in every run level. For more information about the commands and startup scripts, see the Linux documentation.

Once you set up the MySQL service to run automatically and start the MySQL server, you're ready to test your installation.

Installing MySQL On Mac

  1. Download MySQL using a Mac OS X 10.2 (Jaguar) or later PKG binary package.

    Warning:If your operating system is OS X 10.1 or earlier, you can't use this package. You will need to download a tarball and install MySQL from source code.

  2. After the download is complete, change to the download directory - for instance, /usr/local.

    You see a package named mysql-standard-, followed by the version number and the OS number and dmg, such as mysql-standard-5.0.22-osx10.3- powerpc.dmg. If the downloaded file does not have the extension .dmg, change the filename to give it the .dmg extension.

  3. Verify the file you just downloaded.
  4. Create a user and a group named mysql for MySQL to run under. In most newer Mac versions, this user and group already exist.
  5. Mount the disk image by double-clicking its icon in the Finder.
  6. Double-click the package icon to install the MySQL package.

    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 and initializes the database by running the script mysql_install_db, which creates a MySQL account called root.

  7. If necessary, change the owner of the mysql directory.

    The directory where MySQL is installed (for example, /usr/local/ mysql-5.0.22) should be owned by root. The data directory (such as /usr/local/mysql-5.0.22/data) should be owned by the account mysql. Both directories should belong to the group mysql. If the user and group are not correct, change them with the following commands:

    sudo chown -R root /usr/local/mysql-5.0.22
    sudo chown -R mysql /usr/local/mysql-5.0.22/data
    sudo chown -R root /usr/local/mysql-5.0.22/bin
  8. Start the My SQL server using the following commands:
    cd /usr/local/mysql
    sudo./bin/mysqld_safe
    if necessary, enter your password
    Press Ctrl-Z
    bg
    Press Ctrl-D or type exit

    This starts the server manually, meaning you must start the MySQL server every time you restart your computer. To have your 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 separate installation package. To install the Startup Item, double-click the MySQLStartupItem.pkg icon.

To stop the MySQL server, change to the bin subdirectory in the directory where MySQL is installed and type

mysqladmin -u root -p shutdown

Note: The -p causes mysqladmin to prompt you for a password. If the account doesn't require a password, don't include -p.

Verifying a Downloaded File

As a security precaution, the MySQL web site provides methods to verify the software after you download it to make sure the file has not been wrongfully altered. You can verify using either the MD5 method or the PGP method. The MD5 method is simpler and is described in this section.

On the MySQL download web pages a long string called a signature, is displayed next to the file you downloaded, similar to:

MD5: 5170ecdeeb65aaf36415d026e7c5487e

Note: The signature of the file you downloaded for MySQL must match the MD5 signature shown on the MySQL download page.

A Linux or Mac system includes software to check the MD5 signature. On Windows, you may need to download and install MD5 software. A simple, open source (free) Windows program with a GUI that allows you to check MD5 signatures is available.

You can install this software as per their licensing rules.

Once installed, verify the MD5 signature of a file on Windows. Open the file in a Nullriver window as shown and compare the signature from the source (MySQL website): compare the signature

Verifying a MySQL Installation

Here are some simple tests to verify if:

  • MySQL has been installed successfully
  • The server is running
  • Base tables have been initialized

These commands are run from an O/S prompt, preferably from the MySQL installation directory.

mysqladmin: Obtain Server Status

The mysqladmin utility is usually located in the bin subdirectory of your MySQL installation. You can execute it by changing to that directory and executing a few commands. It is best to have mysql binaries in your path, to avoid specifying the path you run everytime.

Note: The location of programs will depend on the OS and the install method. For example, if you used a tar file to install MySQL, the path may be /usr/local/mysql/bin. For RPM-based install, the path may be /usr/bin. On Windows, the path will likely be: c:\Program Files\MySQL\MySQL Server 5.0\bin.

  1. Verify MySQL version. Do this simply to verify that MySQL was properly installed.

    You need to be using an account that has permissions to successfully run the rpm command, such as a root account.

  2. Under the MySQL bin directory, verify:

    Code Sample:

    mysqladmin --version
    Code Explanation

    Information about the MySQL installation displays, including information about the version number and the edition of the MySQL server.

mysql: Is Server Running?

  1. Test whether the server is running. In another command prompt window, change to the bin directory and run the mysql client:

    Code Sample:

    mysql -uroot -p
    Code Explanation

    If the MySQL server is not running, mysql client will give an error like:

    ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

Query on Base Tables

  1. Check whether base tables are initialized after launching the mysql client above:

    Code Sample:

    SELECT Db, User FROM mysql.db;
    Code Explanation

    This query lists database and users to check if core tables exist.

Launching the MySQL Server

This section summarizes the starting and shutting down of the MySQL server.

  • Windows: Under Windows, the simplest way to restart the server is to execute MYSQL SYSTEM TRAY MONITOR. This is a small icon on the task bar (near the clock), in which you can execute the commands SHUTDOWN INSTANCE (end the server) and START INSTANCE.
  • If SYSTEM TRAY MONITOR does not run, launch the program in the menu START | PROGRAMS | MYSQL. If the program does run but is not shown in the task bar, the problem is usually the task bar setting. Click the task bar with the right mouse button, execute the command TASKBAR, and deactivate the option HIDE INACTIVE ICONS.
  • Linux: Under Unix/Linux, the process is somewhat organized around commands, so we execute a command.

    To restart, you use the relevant Init-V script, which you execute first with the parameter stop and then with the parameter start. Depending on the distribution, this script has the name mysql or mysqld.

    root# /etc/init.d/mysql[d] restart

Please note that changes in configuration files become effective only after a restart of the MySQL server.

Installing From Source Files

If an Install Program is available for your operating system, it is best to use it for various reasons. Consider other install options such as building MySQL from source when a binary is not available for your operating system or when you need some additional functionality that's not compiled into the binaries (for example, a special disk driver or a different character set).

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. They offer convenience and a more reliable build.

In other words, if neither an RPM file nor a binary works for you, you can always install MySQL from source files. Before you venture further into this, it is best to get all the facts together and have a very good reason to go this route. The source-based installation process is out-of-scope in this lesson.

Installing MySQL Conclusion

In this lesson of the MySQL tutorial, we reviewed the MySQL installation process.

To continue to learn MySQL  click on the next lesson in this MySQL Tutorial's Table of Contents.
 


mysql tools