Online Book Reader

Home Category

MySQL in a Nutshell [12]

By Root 22060 0
file, the installer will start the MySQL server automatically. If you’ve installed MySQL manually without an installer, enter something like the following from a DOS command window:

mysqld --install

net start mysql

All that remains are some postinstallation adjustments that are explained in the next section.

Postinstallation

After you’ve finished installing MySQL on your server, you should perform a few tasks before allowing others to begin using the service. You may want to configure the server differently by making changes to the configuration file. At a minimum, you should change the password for the root user and add some nonadministrative users. Some versions of MySQL are initially set up with anonymous users. You should delete them. This section will briefly explain these tasks.

Although the MySQL developers have set the server daemon to the recommended configuration, you may want to set the daemon differently. For instance, you may want to turn on error logging. To do this, you will need to edit the main configuration file for MySQL. On Unix systems, this file is /etc/my.cnf. On Windows systems, the main configuration file is usually either c:\windows\my.ini or c:\my.cnf. The configuration file is a simple text file that you can edit with a plain-text editor, not a word processor. The configuration file is organized into sections or groups under a heading name contained in square brackets. For instance, settings for the server daemon mysqld are listed under the group heading [mysqld]. Under this heading, you could add something like log = /var/log/mysql to enable logging and to set the directory for the log files to the one given. You can list many options in the file for a particular group. For a complete listing and explanation of these options, see Chapter 15.

You can change the password for the root user in MySQL in a few ways. One simple way is to log in to MySQL through the mysql client by entering the following from the command line:

mysql -u root -p

On a Windows system, you may have to add the path c:\mysql\bin\ to the beginning of this line, if you haven’t added it to your command path. After successfully entering the command, you will be prompted for the root user’s password. This is not the operating system’s root user, but the root user for MySQL. Initially there is no password, so press Enter to leave it blank. If everything was installed properly and the mysqld daemon is running, you should get a prompt like this:

mysql>

This is the prompt for the mysql client interface. You should set the password for all root users. To get a list of users and their hosts for the server, execute the following command from the mysql client:

SELECT User, Host FROM mysql.user;

+------+-----------------------+

| User | Host |

+------+-----------------------+

| root | 127.0.0.1 |

| root | russell.dyerhouse.com |

| root | localhost |

+------+-----------------------+

The results from my server are shown here. After installing, I have three user and host combinations. Although 127.0.0.1 and localhost translate to the same host, the password should be changed for both along with the one for my domain. To change the root user’s password, enter the following at this prompt:

SET PASSWORD FOR 'root'@'127.0.0.1'=PASSWORD('password');

SET PASSWORD FOR 'root'@'russell.dyerhouse.com'=PASSWORD('password');

SET PASSWORD FOR 'root'@'localhost'=PASSWORD('password');

Replace the word password in quotes with the password that you want to use for root. On some systems, the wildcard % is used to allow root login from any host. After you change all of the root passwords, log out of the mysql client and log back in with the new password.

On some older systems or versions of MySQL, there are anonymous users. (Newer editions don’t have them.) They will appear in the results of the SELECT statement shown earlier with blank fields for usernames. You should delete them by entering the following from the mysql client:

DELETE FROM mysql.user WHERE User='';

DELETE FROM mysql.db WHERE User='';

FLUSH PRIVILEGES;

Return Main Page Previous Page Next Page

®Online Book Reader