Robin Dupont
Robin Dupont

Reputation: 339

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.

Upvotes: 21

Views: 30593

Answers (8)

goulashsoup
goulashsoup

Reputation: 3076

In my case the mysql root password was my superuser password.

Upvotes: 1

ankit tyagi
ankit tyagi

Reputation: 846

In my case nothing worked as mentioned here, following worked for me. As described here also: https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html

A superuser account 'root'@'localhost is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:

shell> sudo grep 'temporary password' /var/log/mysqld.log

Upvotes: 2

Rajan Verma - Aarvy
Rajan Verma - Aarvy

Reputation: 2117

If someone facing this problem in installing MYSQL in Ubuntu 18.04.

Ubuntu 18.04 uses sockets for authorization and not passwords!!

(https://websiteforstudents.com/mariadb-installed-without-password-prompts-for-root-on-ubuntu-17-10-18-04-beta/)

For me logging in was as simple as:

sudo  mysql -u root      

Don't forget the sudo

I really hope there should have been a message stating that Ubuntu no longer used passwords when attempting to run mysql. this was a really drastic change in functionality.

Upvotes: 5

Nandesh
Nandesh

Reputation: 4633

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.

Upvotes: 25

Mr.Throg
Mr.Throg

Reputation: 1005

Download apt repository from mysql official site https://dev.mysql.com/downloads/repo/apt/

Select your version and click next and select ok and click next.

now

sudo apt-get update  

sudo apt-get install mysql-server

while installing it will ask for password.

Upvotes: 1

Enoobong
Enoobong

Reputation: 1734

I had the same problem which prevented me from being able to access mysql all the answers to use mysql_secure_installation after running sudo apt install mysql-server didn't work. Here's what worked

  1. Go to official mysql installation guide and follow line by line
  2. You need to download a .deb file from here that configures which version of mysql you want to install and other configurations
  3. After configurations are all done run sudo apt-get update && sudo apt-get install mysql-server This time you'd be asked for a password.

Hope it helps. Cheers!

Upvotes: 1

corporateWhore
corporateWhore

Reputation: 635

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

Upvotes: 30

mszmurlo
mszmurlo

Reputation: 1339

You might be interested reading this question and aswers.

Isn't the default password the empty string ?

Upvotes: 0

Related Questions