After MySQL has been successfully installed, the base tables have been initialized, and the server has been started, you can verify that all is working as it should via some simple tests.
Note that all these commands should be run from your UNIX or Windows command prompt. I am assuming here that you are running them from your MySQL installation directory (as per the examples in the section “Installing and Configuring MySQL,” this will be either /usr/local/mysql in UNIX or c:\program files\ mysql in Windows).
Use the mysqladmin Utility to 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 the following command:
[root@host]# mysqladmin version
You should see something resembling the output shown in Figure 3-22.
Connect to the Server Using the MySQL Client, and Execute Simple SQL Commands
The MySQL client that ships with the MySQL distribution is named, funnily enough, mysql. Fire it up from your command prompt by switching to the bin directory of your MySQL installation and typing
You should be rewarded with a mysql> prompt. At this point, you are connected to the MySQL server and can begin executing SQL commands or queries. Here are a few examples, with their output:
mysql> SHOW DATABASES;
mysql> USE mysql;
mysql> SHOW TABLES;
mysql> SELECT COUNT(*) FROM user;
Once testing is complete, you should perform two more tasks to complete your MySQL installation:
Alter the MySQL root Password
When MySQL is first installed, access to the database server is restricted to the MySQL administrator, aka root. By default, this user is initialized with a null password, which is generally considered a Bad Thing. You should therefore rectify this as soon as possible by setting a password for this user via the included mysqladmin utility, using the following syntax in UNIX
[root@host]#/usr/local/mysql/bin/mysqladmin -u root
password ' <new-password>'
C:\> c:\program files\mysql\bin\mysqladmin -u root
password ' <new-password>'
This password change goes into effect immediately, with no requirement to restart the server or flush the privilege table.
Configure MySQL to Start Automatically When the System Boots up
On UNIX, MySQL comes with a startup/shutdown script, which is the recommended way of starting and stopping the MySQL database server. This script, named mysql.server, is available in the support-files subdirectory of your MySQL installation, and it can be invoked as follows:
[root@host]# /usr/local/mysql/support-files/mysql.server start
To have MySQL start automatically at boot time, you simply need to copy this script to the /etc/init.d/* directory hierarchy of your system, and then you can invoke it with appropriate parameters from your system’s bootup and shutdown scripts.
To start MySQL automatically on Windows, you can simply add a link to the mysqld server binary to your Startup group. For more information, please refer to Chapter 13.
As a popular open-source application, MySQL is available for a wide variety of platforms and architectures, in both binary and source form. This chapter explained the distinction among the different versions of MySQL, together with recommendations on the most appropriate version for your requirements; it also demonstrated the process of installing MySQL on the two most common platforms, Linux and Windows. It provided installation and configuration instructions for both binary and source distributions and also provided pointers to online resources for other platforms and for detailed troubleshooting advice and assistance.
blog comments powered by Disqus