JavaScript Editor Js editor     Website development 



Main Page

Previous Page
Next Page

Setting the Root User Password

One of the most important uses of mysqladmin is to assign a password to the root user. When MySQL is installed, no such value is established. This is certainly a security risk that ought to be remedied before you begin to use the server.

Just to clarify, your databases can have several users, just as your operating system might. But the MySQL users are different from the operating system users, even if they share a common name. Therefore, the MySQL root user is a different entity than the operating system's root user(if one exists), having different powers and even different passwords (preferably but not necessarily).

If you used the MySQL Instance Configuration Wizard on Windows (see Chapter 1), you should hopefully have already assigned a password to the root user. Otherwise, follow these steps.

To assign a password to the root user:

1.
Log in to your system from a command-line interface.

2.
Move to the MySQL installation directory.

This might be either

cd/usr/local/mysql (Mac OS X and Unix)

or

cd C:\"Program Files\MySQL\MySQL Server 5.0" (Windows)

The full path may also differ for you, so change these commands as necessary.

3.
Enter one of the following, replacing theNEWpassword with the password you want to use (Figure 2.28):

Figure 2.28. Use mysqladmin to establish a password for the root user.


bin\mysqladminu root password 'theNEWpassword' (Windows)

or

./bin/mysqladmin u root password 'theNEWpassword' (Mac OS X and Unix)

Keep in mind that passwords within MySQL are case-sensitive, so Kazan and kazan are not interchangeable. The term password that precedes the actual quoted password tells MySQL to encrypt the password that follows.

Once you've established the root user's password, it's only slightly more complicated to change it.

To change the root user's password:

1.
Log in to your system from a command-line interface.

2.
Move to the MySQL installation directory.

3.
Enter one of the following, replacing newNEWpassword with the password you want to use:

bin/mysqladminu root -p password 'newNEWpassword' (Windows)

or

./bin/mysqladminu root -p password 'newNEWpassword' (Mac OS X and Unix)

Because it has already been established, the root user's password is required to use the mysqladmin tool from here on out. The -p argument will make mysqladmin prompt you for the current password.

4.
At the prompt, enter the current (or soon-to-be-old) root userpassword (Figure 2.29).

Figure 2.29. To change an existing root user's password, add the -p option to your mysqladmin line (Figure 2.28) so that you'll be prompted for current password.


Tip

  • It can, and unfortunately does, happen that you forget or misplace the root userpassword, essentially locking the most important user out of the database. To fix this should it happen, see Appendix A, "Troubleshooting," where I'll walk you through the solution.



Previous Page
Next Page


JavaScript Editor Js editor     Website development


©