Same root password setting problem here, mine possibly caused by an unsuccessful manual installation of mysql server 5.6 previously. A thorough mysql uninstallation is no easy task. I purged/reinstalled for hours then finally solved it with
sudo dpkg --purge mysql-client-core-5.5 # or alternative version
sudo dpkg --purge mysql-client
sudo dpkg --purge mysql-server-core-5.5 # or alternative version
sudo dpkg --purge mysql-common
Basically I just type
sudo dpkg --purge mysql # followed by two tabs
Then --purge
any packages the terminal auto-completes. Purge mysql-common
at last because of some dependency problems.
Use above dpkg
commands in addition to
sudo apt-get --purge remove mysql-server
sudo apt-get --purge remove mysql-client
sudo apt-get --purge remove mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
Also I tried Greq's method
sudo rm -rf /etc/mysql
Remove the mysql folder from /var/lib
sudo rm -rf /var/lib/mysql/
At this point, to make sure mysql is fully removed, check with
which mysql
mysql --version
The first one should return no output instead of a folder. The second should return mysql is not installed instead of a version number. Otherwise the removal is still incomplete.
The significance of dpkg --purge
is, when using apt-get
alone, which mysql
and mysql --version
behave like mysql is still there.
Before reinstallation, reconfigure dpkg and update
sudo dpkg --configure -a
sudo apt-get update
Problem resolved finally. Hope it will be helpful for other people.
Add switch -p
for password based login:
mysql -u root -p
That is the normal behaviour. You set a root password for your database so from now on you can't access it without password. That is why it reports:
Access denied for user 'root@localhost' (using password: no )
Obviously when you give the password with the -p
switch you succeed.
Best Answer
For the new my-sql 5.7 if password is left empty then it uses auth_plugin.
In that case login with
sudo
privilege.After login you can simply use this to update password.
For complete refrence check here.
EDIT: One can also use this (without
-u root
):