Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fresh mysql-server installation does not ask for password

I am installing the package mysql-server on debian (actually Raspbian, the Debian version for raspberry pi). I'm installing it with the following command

sudo apt-get install mysql-server

During the installation I'm not asked to enter a root password. And if I try to connect to mysql with the following command :

mysql -u root

or

mysql -u root -p

and using the system root password, I got the following error :

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

I am quite confused since apparently I should be asked to provide a root password during the installation.

What should I do ?

Regards.

like image 498
Robin Dupont Avatar asked Nov 09 '17 21:11

Robin Dupont


2 Answers

Try this:

After installation, run MySql Secure Installation:

pi@raspberrypi:~ $ sudo mysql_secure_installation

You'll be asked a series of security related configuration questions, including setting the root password.

Once the root password is set, you'll need to be logged in as root (or use sudo) to login. This is a consequence of how MySql uses credentials based on process uid

like image 142
corporateWhore Avatar answered Oct 08 '22 07:10

corporateWhore


Here you go:

In the new my-sql if the password is left empty while installing then it is based on the auth_socket plugin.

The correct way is to login to my-sql with sudo privilege.

$ sudo mysql -u root -p

And then updating the password using:

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

Once this is done stop and start the mysql server.

$  sudo service mysql stop
$  sudo service mysql start

For complete details you can refer to this link.

Do comment for any doubt.

like image 22
Nandesh Avatar answered Oct 08 '22 09:10

Nandesh