user6227077
user6227077

Reputation:

how to recover mysql password in ubuntu 16.04

Mysql version - mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using EditLine wrapper.

I had forgotten my password and tried many commands online.Also the problem is that grant tables command not working in my terminal.

Upvotes: 6

Views: 9549

Answers (4)

Wasimkhana
Wasimkhana

Reputation: 21

I had tried all the approaches but didn't work for me. The following approach worked. I am hopeful that it will work on different versions of ubuntu.

  1. OS info:
mysql --version
mysql  Ver 8.0.28-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
  1. First, stop MySQL service using command
sudo systemctl stop mysql
  1. Other commands didn't work and here how I start the MySQL server without any permission-checking. To do so, run:
// open the mysql systemd configuration file your default text editor. 
// In my case, it is nano editor.
sudo systemctl edit mysql

// Add the following 3 lines
[Service]
ExecStart=
ExecStart=/usr/sbin/mysqld --skip-grant-tables --skip-networking
  1. Reload systemd configuration using command:
sudo systemctl daemon-reload
  1. Start MySQL service
sudo systemctl start mysql
  1. Now, connect to MySQL server as root user without password:
sudo mysql -u root
mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'add-newpassword-here';
  1. Revert the modified systemd configuration
sudo systemctl revert mysql

You are all Done.

Upvotes: 0

Worik
Worik

Reputation: 152

~$ cat /etc/issue
Ubuntu 16.04.3 LTS \n \l

~$ aptitude show mysql-server |grep Version
Version: 5.7.20-0ubuntu0.16.04.1

In file: /etc/mysql/debian.cnf are two important lines:

user     = debian-sys-maint
password = <unique password>

Use that user and password to login to mysql: Once logged in as debian-sys-maint you can:

FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Upvotes: 15

Yang Li
Yang Li

Reputation: 21

The following adjustments works for my setup:

$ sudo mkdir /var/run/mysqld
$ sudo chown mysql: /var/run/mysqld
$ sudo kill -9 $(sudo cat /var/run/mysqld/mysqld.pid)

Upvotes: 2

Pankaj Gupta
Pankaj Gupta

Reputation: 26

1) Stop the Database Server. sudo systemctl stop mysql

2) Restarting the Database Server Without Permission Checking. For this following command sudo mysqld_safe --skip-grant-tables --skip-networking &

3) Connect to the database as the root user mysql -u root

4) Change the Root Password

FLUSH PRIVILEGES;

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

5) Restart the database server narmally

sudo kill `cat /var/run/mysqld/mysqld.pid`

sudo systemctl start mysql

Now login with new password in database: mysql -u root -p

Or you can follow the following link:

https://www.digitalocean.com/community/tutorials/how-to-reset-your-mysql-or-mariadb-root-password

Upvotes: 0

Related Questions