Ubuntu – Problem with thesql root password

MySQLpasswordroot

I am on Ubuntu 16.04 LTS. What is my mysql root password? If I enter

mysql -u root -p

It asks me to enter a password: I don't know it, and no password won't work either. Mysql was pre-installed, so I didn't choose any root password. If I try to install it again, with

sudo apt-get install mysql-server

It says that mysql-server is already the newest version (5.7.18-0ubuntu0.16.04.1)

Any help, hints? Thanks.

Best Answer

For the new my-sql 5.7 if password is left empty then it uses auth_plugin.

In that case login with sudo privilege.

$ sudo mysql -u root -p

After login you can simply use this to update password.

$ ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new-password';

For complete refrence check here.

EDIT: One can also use this (without -u root):

$ sudo mysql
$ ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new-password';