How to get mysql initial root password? [duplicate]
After installing mysql using sudo apt-get install mysql-server, no question was asked to me to fill a specific password for root account. Logically, it means password is empty. It is confirmed when I have a look in the /var/log/mysql/error.log where I can find this information =>
2019-04-28T20:31:35.761063Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.But now, when I connect to PHPAdmin with root login and empty password, I have a message:
#1698 - Access denied for user 'root'@'localhost'with a few more details:
mysqli_real_connect(): (HY000/1045): Access denied for user 'phpmyadmin'@'localhost' (using password: YES)How do I solve this issue?
32 Answers
With Ubuntu 18.04 and mysql-5.7, the default method for a mysql root login has changed,
now you have to be the superuser (either by doing sudo mysql -u root or by calling a root shell sudo bash first). Since you are already authenticated as the root user, no password is needed any longer.
See also this question and its answers.
You can change the password and set a new root password by doing this :
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';skip-grant-tables option enables anyone to connect without a password and with all privileges
2