MySQL I : Setting the root password

1. By default, when you install MySQL, no password is set. This is considered insecure. On Windows, the easiest way to initially change the username and password is to run “Winmysqladmin.exe”. We did this, but canceled the setup user / password dialog. We will use instead the command line method.
2. MySQL users are different from operating system users. Your database can have many users. The master MySQL user is ‘root’, which is different from the Linux ‘root’ user or Windows ‘administrator’.
3. Passwords are case sensitive.
4. To set the initial ‘root’ user password, on Windows and Linux/UNIX, open a command shell.
5. Windows: cd c:\mysql\bin
Linux: cd /usr/local/mysql/bin
6. Set the password: mysqladmin –u root password “mynewpassword”
– and Press Enter. You will not be prompted for a password. Since this is a brand new installation, you do not have a password yet.
7. Test your new root password. Type: mysql –u root –p
And type your password: mynewpassword
8. You are in the MySQL Monitor client. Type: quit
9. Try entering a bad password, and seeing what happens. Type:
C:\mysql\bin>mysql -u root –p
Enter password: abc

ERROR 1045: Access denied for user: ‘root@localhost’ (Using password: YES)
C:\mysql\bin>

Note that the root account is tied to the “localhost” loopback address (root@localhost)
10. You can change the root user’s password (be careful!) by typing:
mysqladmin –u root –p password “mypass”
And type your old password: mynewpassword
– The –p argument makes mysqladmin prompt you for the current (old) password.
11. Test your new root password. Type: mysql –u root –p
And type your password: mynewpassword
12. You are in the MySQL Monitor client. Type: quit
13. Don’t lose your root password. If you do, you can follow the method to reset your password described in Appendix A of your book. (optional: Page 282)
14. To check if MySQL is running type:
mysqladmin –u root –p ping
15. To check which version of MySQL you are running type:
mysqladmin –u root –p version