44

I'm trying to set the password of the user root but I'm gettin the error below, any idea?

+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*436576511F70A4E3B305E1AB8E209851945D8687' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


mysql> exit
Bye
root@tirengarfio:/var/www/rs2# mysqladmin -u root password foo,
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
tirenweb
  • 30,963
  • 73
  • 183
  • 303
  • Error 1045 is explained here: http://faq.webyog.com/content/23/18/en/error-no-1045-connection-denied.html – Ashwin A Nov 22 '12 at 07:41
  • [If using Debian or Ubuntu, and you want to reset everything and the tables and connect.](http://askubuntu.com/q/696964/29097) – Evan Carroll Nov 12 '15 at 00:24

8 Answers8

47
$ mysqladmin -u root -p password
Enter password: 
New password: 
Confirm new password:

password is to be typed literally. It's a command. You don't have to substitute password with your actual password.

Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
djrconcepts
  • 635
  • 5
  • 6
37
# /etc/init.d/mysqld stop

Stopping MySQL: [ OK ]

# mysqld_safe --skip-grant-tables &

[1] 13694

# Starting mysqld daemon with databases from /var/lib/mysql



# mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.0.77 Source distribution



Type 'help;' or '\h' for help. Type '\c' to clear the buffer.



mysql>
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • 6
    I has almost same problem, and I also had to reset the mysql password. First I ran the steps above, then with the help of [nixcraft](http://www.cyberciti.biz/faq/mysql-change-root-password/) had to do:
    `# use mysql;`
    `mysql> update user set password=PASSWORD("NEWPASSWORD") where User='root';`
    `mysql> flush privileges;`
    `mysql> quit`
    – ungalcrys Nov 12 '13 at 21:23
  • 3
    This doesn't work at all. mysqld_safe fails immediately with: `2017-05-07T00:11:22.676724Z mysqld_safe Logging to '/var/log/mysql/error.log'. /usr/bin/mysqld_safe: 150: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied 2017-05-07T00:11:22.680077Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists. /usr/bin/mysqld_safe: 150: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied` – Cerin May 07 '17 at 00:12
8

Set/Change password:

mysqladmin -u root -p password

Login to MySQL console:

mysql -u root -p

To exit the console:

.\q
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
MiDo
  • 1,057
  • 1
  • 7
  • 11
  • 1
    How to authenticate to mysqladmin? – KMC Sep 19 '12 at 07:39
  • 1
    It's written right there, `mysqladmin -uroot -poldpassword password newpassword` - that is how you authenticate as a valid user with access rights and issue the command to change the password. Did you -1 my answer? – MiDo Sep 21 '12 at 14:26
  • 5
    jAckOde : Please see http://meta.stackexchange.com/questions/147616/what-do-you-mean-it-doesnt-work – MiDo Nov 16 '12 at 16:42
2

when trying to run this command i got the same error

sudo mysqladmin create asteriskcdrdba

i simply add a few lines to the code

-u root -p

and pressed the enter key. i then typed my password and hit enter. Linux liked my command as nothing more was displayed

so maybe try

sudo <your command here> -u <username> -p

after that hit enter and enter your password

kevin jack
  • 37
  • 1
2

Those are all good answers, but don't quite touch the deep cause of the problem one most likely has if faced with the OP question. That is, not knowing the ORIGINAL "starting" password created during the installation time.

And all these command lines with "-u root ..." etc. imply knowing and using THAT password.

Now this part from the original installation message may help anyone facing the problem above:

Initial password for first time use of MySQL is saved in $HOME/.mysql_secret
ie. when you want to use "mysql -u root -p" first you should see password
in /root/.mysql_secret

1

This is basically a more detailed version of a previous answer.

In your Terminal, go to the location of your utility program, mysqladmin

For example, if you were doing local development and using an application like M/W/XAMP, you might go to the directory:

/Applications/MAMP/Library/bin

This is where mysqladmin resides.

If you're not using an application like MAMP, you may also be able to find your local installation of mysql at: /usr/local/mysql

And then if you go to: /usr/local/mysql/bin/

You are in the directory where mysqladmin resides.

Then, to change the password, you will do the following:

  1. At your Terminal prompt enter the exact command below (aka copy and paste) and press enter. The word "password" is part of the command, so don't be confused and come to the conclusion that you need to replace this word with some password you created previously or want to use in the future. You will have a chance to enter a new password soon enough, but it's not in this first command that you will do that:

    ./mysqladmin -u root -p password

  2. The Terminal will ask you to enter your original or initial password, not a new one yet. From the above image you provided, it looks like you have one already created, so enter it here:

Enter password: oldpassword

  1. The Terminal will ask you to enter a new password. Type it here and press enter:

New password: newpassword

  1. Then the Terminal will ask you to confirm the new password. Type it here and press enter:

Confirm new password: newpassword

Reset or restart your Terminal.

In some cases, as with M/W/XAMP, you will have to update this new password in various files in order to get your application running properly again.

robkriegerflow
  • 716
  • 5
  • 13
-2
  • open my.cnf using following path

C:\xampp\mysql\bin

  • under # The following options will be passed to all MySQL clients #password remove # comment sign if it is there password = "newpassword"

  • save file

  • close file

  • re-start mysql

Saty
  • 22,443
  • 7
  • 33
  • 51
Mirza
  • 1
-2

Firstly, go to the folder support-files on terminal, and start the server by mysql.server start, Secondly, go to the folder bin on terminal or type /usr/local/mysql/bin/mysqladmin -u root -p password

It would ask you for the old temporary password which was given to you while installing Mysql, type that and type in your new password and it would work.

sunny
  • 57
  • 3