No password is asked when installing mysql-server

January 15, 2017 55.5k views
MySQL LAMP Stack Ubuntu 16.04

No password is asked when installing mysql-server.
this is the output I have from the terminal :

root@mizzouadvantagecod:~# sudo apt-get install mysql-server
Reading package lists… Done
Building dependency tree

Reading state information… Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/10.1 kB of archives.
After this operation, 106 kB of additional disk space will be used.
Selecting previously unselected package mysql-server.
(Reading database … 85555 files and directories currently installed.)
Preparing to unpack …/mysql-server5.7.16-0ubuntu0.16.04.1all.deb …
Unpacking mysql-server (5.7.16-0ubuntu0.16.04.1) …
Setting up mysql-server (5.7.16-0ubuntu0.16.04.1) …

1 comment
  • When I was following along the Digital Ocean guide, my Ubuntu 18.04 server did not ask to set the MySQL root user password during apt-get install mysql-server. I was able to login to MySQL and manually set the password using the following commands

    sudo mysqld_safe --skip-grant-tables&
    sudo mysql --user=root mysql
    mysql> update user set authentication_string=PASSWORD('new-password') where user='root';
    flush privileges;
    sudo service mysql restart
    sudo mysql -u root -p

    I then needed to run mysql_secure_installation using the sudo command

    sudo mysql_secure_installation

    The sudo was not mentioned in the guide. When I ran it without sudo, I got the following error:
    Error: Access denied for user ‘root’@'localhost’

    Hope this is helpful for others.

5 Answers

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!

try Dimitre’s answer here:
you can set the mysql root password before installation

It’s now fixed:

Remove all files related to MySQL

sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean

Then upgrade my distribution

sudo apt-get dist-upgrade

Then install MySQL

sudo apt-get install mysql-server
That’s all.


As a general note, depending on the OS and the decision of the package manager, a password may not be required during package installation.

To remedy that, and something you should run after installing MySQL or MariaDB anyway:


Simply follow the on-screen prompts and it’ll handle setting the root password (or changing it) as well as removing un-needed items from the core.

Check the mysql logs:
grep ‘temporary password’ /var/log/mysqld.log

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!