To set a root password for MySQL, type the following command in the bin directory
of your MySQL installation:
Code:
mysql -u root mysql
This command connects you to your newly-installed MySQL server as the root user, and chooses the mysql database. After a few lines of introductory text, you should see the MySQL command prompt (mysql>). To assign a password to the root user, type the following three commands (pressing Enter after each one):
Code:
mysql>SET PASSWORD FOR root@localhost=PASSWORD("new password");
Query OK, 0 rows affected (0.00 sec)
mysql>SET PASSWORD FOR root@"%"=PASSWORD("new password");
Query OK, 0 rows affected (0.00 sec)
mysql>FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
Be sure to replace both instances of new password with the password you want to assign to your root user. The first command sets the password required when connecting from the machine on which the server is running; the second sets the password for all other connections.
With that done, disconnect from MySQL with the quit command:
Now, to try out your new password, at the system command prompt again, request that the MySQL server tell you its current status:
Code:
mysqladmin -u root -p status
Enter your new password when prompted. You should see a brief message that provides information about the server and its current status. The -u root argument tells the program that you want to be identified as the MySQL user called root. The -p argument tells the program to prompt you for your password before it tries to connect. The status argument just tells it that you're interested in viewing the system status.
Bookmarks