How to set up a password for root user in MySql Setting MySql root password
By default, MySql comes with no password for localhost root user and with access to the console, any could have access to all databases also.
Set MySql root password:
$ mysqladmin -u root password newpassword
Replace "newpassword" with your new password (and make sure you remember it).
From now on, mysql will deny access to the database unless you provide -p argument to mysql command at the shell prompt.
$ mysql mydatabase ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
It will request from you the password when connecting to the database. To connect to the mysql database with your new password, issue the following command:
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 553 Server version: 5.1.20-beta-log FreeBSD port: mysql-server-5.1.20
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>
Now you have your database protected against local unauthorized people.
Change MySql root password:
Now that you have a password for mysql root user and you need to change it (doesn't work with mysqladmin -u root oldpass new pass, at least for me it didn't work).
Login as root and root password to mysql database:
$ mysql -u root -p mysql Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 581 Server version: 5.1.20-beta-log FreeBSD port: mysql-server-5.1.20
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> set password for root@localhost=PASSWORD('hondad16z6'); Query OK, 0 rows affected (0.00 sec)
mysql> SET PASSWORD FOR root@localhost=PASSWORD('newpassword'); mysql> Bye
And now log back in with root user and newpassword. There you have it :).-------------------advertising-----------------
Designed and developed by Andrei Manescu. Optimized for Mozilla Firefox.
Copyright 2007 Andrei Manescu
All trademarks and copyrights on this page are owned by their respective owners. Comments are owned by those who posted them.