I installed mysql-server and it did not ask for a root password, and now i can't log into MySQL as root. Also, i noticed, that command "mysql_secure_installation" wants to secure a MariaDB database root account, not a MySQL one. I have been trying for days, but nobody could help me anywhere. What may the solution be? (Debian 9)

  • How do you try to connect, what is the error message. If you can't login you can always set a new password. – deagh Feb 23 '18 at 16:44
  • with "sudo mysql" and it gives me a MariaDB prefix, and with "\r mysql" command i can manage SQL. But why isn't it asking the root password for mysql? – tommy716 Feb 23 '18 at 16:59
  • mariadb is the drop-in replacement for MySQL in Debian (and other distributions). As long you didn't run mysql_secure_installation you have no default root password and can login with mysql -u root -h localhost – deagh Feb 23 '18 at 17:02
  • i was able to use mysql-server some time ago on debian, it even asked for a password when installing. on ubuntu it still asks for a password now, but not on debian. this makes it installing harder. but when i run mysql_secure_installation it asks for a current root password. – tommy716 Feb 23 '18 at 17:19

After initial installation you should run mysql_secure_installation to set a password for root accounts. https://mariadb.com/kb/en/mariadb/mysql_secure_installation/

MariaDB Server is the default fork of MySQL in Debian 9.



In Debian 9 "Stretch" the mysql-server package depends on a new package called default-mysql-server. This package in turn depends on mariadb-server-10.1.

[..] when you install the mysql-server package on Stretch you will get MariaDB 10.1 instead of MySQL, like you would with previous versions of Debian. Note that mysql-server is just an empty transitional meta-package and users are encouraged to install MariaDB using the actual package mariadb-server.

source: https://mariadb.com/kb/en/library/moving-from-mysql-to-mariadb-in-debian-9/

  • but whenever i run it it asks me to confirm with the current root password. i did not set a root password. – tommy716 Feb 23 '18 at 18:40
  • now setting maria db root password was successful, but what about my mysql root password? – tommy716 Feb 23 '18 at 20:10
  • As Fabian mentioned, mariadb replaces mysql. So when you run "apt-get install mysql-server", you will in fact be installing mariadb. Not the original mysql from Oracle. Setting the "maria db root password" is therefore the same as the "mysql root password". You can use mariadb just as you would use mysql, and most client applications wouldn't notice the difference. – Nils Feb 26 '18 at 12:36
  • @tommy716 MariaDB is a fork of MySQL. The secure installation will set the MySQL root password. – Timothy Frew Apr 27 '18 at 23:51

If you find some MySQL/MariaDB commands are running without any password prompt want to see what password it is using behind the scenes, Debian stores the generated passwords in /etc/mysql/debian.cnf

/etc/mysql# cat debian.cnf 
# Automatically generated for Debian scripts. DO NOT TOUCH!
host     = localhost
user     = debian-sys-maint
password = <random string>
socket   = /var/run/mysqld/mysqld.sock
host     = localhost
user     = debian-sys-maint
password = <random string>
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.