1

I was doing everything without success :( I still get error if I try to change mysql root password

What I have done till now: 1)

service mysql stop

2)

mysqld_safe --skip-grant-tables &

3)

mysql -u root

4)

update user SET PASSWORD=PASSWORD("<my_new_password>") WHERE USER='root'; flush privileges; exit

5)

mysql -u root -p 

and...

Im getting whole time:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

My server is ubuntu 16.0.4

Could some tell me please if I reinstall mariaDB I will still have my databases? Right now I can not even do a backup :(

Anna K
  • 1,666
  • 4
  • 23
  • 47
  • 2
    "using password: NO" means you didn't send the password when you tried to connect to the database. Show your code that's trying to connect. – Barmar Mar 08 '18 at 21:09
  • 1
    Ouch... modifying system tables by SQL commands is a no-go and might damage your db (consider e.g. if a user has another default authentication than mysql_native_password) Why don't use SET PASSWORD FOR 'root'@'localhost' ....? I would also recommend to restart MariaDB between steps 4 and 5. – Georg Richter Mar 11 '18 at 06:12

4 Answers4

3

I know this question is old, but I didn't notice an attempt of

sudo mysql -u root

The newer versions of mariadb seem to use linux authorization for the root user, and ignore the password.

roderick young
  • 284
  • 1
  • 10
0

your root user could be missing from the mysql.user table , and so your step (4) does nothing

here is an answer to help restore it: restoring-deleted-root-user-and-password-for-mysql

apapa
  • 669
  • 13
  • 22
-1

Try running sudo mysql_secure_installation

This should prompt you to change your root password as well as a few other things.

Also if you have access to phpmyadmin page then you can export your databases and reinstall mariaDB for backup purposes and then you can import the tables again once you have it reinstalled.

  • I have no phpmyadmin access :/ #1045 - Access denied for user 'skni'@'localhost' (using password: YES) – Anna K May 21 '18 at 09:28
  • Doesn't work in new mariadb installs, because somehow the automatically set root password is NOT empty. There's more discussion in the other question in case someone finds this Stackoverflow (it ranks high on google for some reason) -- https://stackoverflow.com/questions/33510184/how-to-change-the-mysql-root-account-password-on-centos7 – PKHunter Jan 03 '21 at 16:16
-3

Try running mysql -u root -p followed by your password