Setting the root password on MySQL

23 Jan, 2007  |  Posted by Danesh  |  in Linux

I just installed MySQL version 4.1.20 on my CentOS 4.4 server. The default install of MySQL server uses a blank password for root so I had to have it changed. I also set the MySQL service to start up every time my machine boots up.

This is how I did it;

Method 1

1. # yum -y install mysql-server (This will install the mysql binaries)
2. # chkconfig mysqld on (Adds mysqld to the startup services)
3. # service mysqld start (Starts the MySQL server)
4. # mysql -u root@localhost (Brings up the MySQL console)
5. #mysql> set password for root=password(’password’); (Sets the root password to “password”)
6. #mysql> reload privileges; (Reloads the grant tables)

Method 2

1. # mysql -u root (Brings up the MySQL console)
2. #mysql> use mysql (Use the mysql database)
3. #mysql> update user
-> set password=password(”password”) (Sets the root password to “password”)
-> where user=”root”;
4. # reload privileges; (Reloads the grant tables)
That’s it, the next time you want to get the MySQL console up you’ll have to run #mysql -u root -p to get the password prompt.

Post-Installation Setup and Testing at MySQL

Update:

This will work too.

/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h pandora.crib password ‘new-password’

  • Digg
  • del.icio.us
  • BlinkList
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Furl
  • Google
  • Live
  • Facebook
  • Pownce
  • TwitThis
  • E-mail this story to a friend!
Tags: , ,

One Response so far | Have Your Say!

  1. Danesh  |  February 5th, 2007 at 12:50 am #

    In method 1 if you receive an error saying no permission try using just root in place of root@localhost .

    Danesh - Gravatar

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>