I am on Ubuntu 16.04 LTS. What is my mysql root password? If I enter
mysql -u root -p
It asks me to enter a password: I don't know it, and no password won't work either. Mysql was pre-installed, so I didn't choose any root password. If I try to install it again, with
sudo apt-get install mysql-server
It says that mysql-server is already the newest version (5.7.18-0ubuntu0.16.04.1)
Any help, hints? Thanks.
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
):For MySQL 5.7, the default password is printed in the logs. A quick grep can return it.
References: https://www.percona.com/blog/2016/05/18/where-is-the-mysql-5-7-root-password/
https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html
https://stackoverflow.com/questions/33991228/what-is-the-default-root-pasword-for-mysql-5-7
https://dba.stackexchange.com/questions/127537/setting-root-password-in-fresh-mysql-5-7-installation
Two options:
First is purging mysql(only if you don't already have a database):
Use
to purge and then
to simply reinstall it. While installing it should ask you for a password. This is the easiest and fastest way, however it could come to problems if some programs like phpmyadmin already connected to the existing MySQL so I'd suggest you to use the
Or do the following: Stop the MySQL Server using
Then start the safe mode with
Select localhost as host(After the last command there won't be a command prompt, so after the message
Starting mysqld daemon with databases from [...]
type in the next command)select mysql with
(Replace YOURNEWPASSWORD with your new password!) Type
Exit with
And restart MySQL with
Edit
That error has something to do with your MySQL socket. First you want to find all socket files on your system with:
Your socket should be something similar to this
(important is the
/mysql.sock
part)Once you find where the socket is being opened, add or edit the line to your
file with the path to the socket file:
put
at the very beginning and
at the very end of the file.
Try the 2. option again now. If it doesn't work continue with this explanation.
If this doesn't solve your problem something overrides the my.cnf location, and that would result in a socket not being found where the my.cnf file indicates it should be. Then when you try to run the mysql command line client, it will read my.cnf to find the socket, but it will not find it since it deviates from where the server created one. So, Unless you care where the socket resides, just changing the my.cnf to match should work.
To fix this start with shutting down the
mysqld
processAfter you do this you might want to look for a pid file in /var/run/mysqld/ and delete it
Make sure the permissions on your socket is such that whatever user mysqld is running as can read/write to it. An easy test is to open it up to full read/write and see if it still works:
chmod 755 /var/run/mysqld/mysqld.sock
Sources:
https://dev.mysql.com/doc/refman/5.7/en/mysql-commands.html
https://ubuntu.flowconsult.at/en/mysql-set-change-reset-root-password/
https://stackoverflow.com/questions/11990708/error-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysq
UBUNTU 16.04 and MYSQL 5.7.20
I did not find ADDB's instructions completely helpful. After searching I discovered the following (a small re-write for Option 2):
Reference: http://rricketts.com/reset-root-password-mysql-5-7-ubuntu-16-04-lts/
My preferred method:
I used the Mysql user "debian-sys-maint" (a root equivelant). The password can be found in /etc/mysql/debian.cnf. After logging into Mysql as this user change the password for any Mysql user.
Reference: https://serverfault.com/questions/9948/what-is-the-debian-sys-maint-mysql-user-and-more