I am trying to get MySQL running on my localhost. This never happened to me before, but upon installation sudo apt-get install mysql-server
did not ask me for the initial password.
After searching for answers to "reset" my password and battling with directory permissions, i am currently at this state:
The mysqld_safe solution:
- After rebooting my computer,
mysql -u root -p
will ask me for my password, and after i enter it, it will complain withERROR 1698 (28000): Access denied for user 'root'@'localhost'
- If i instead try
mysql -u root
(no password), it will sayERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
- If i run the advice that other people have posted about resetting the password via
mysqld_safe --skip-grant-tables
, then i run across some hiccups along the way:- First i run
sudo service mysql stop
- Then
sudo mysql_safe --skip-grant-tables
will saymysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
- I can fix that if i do
sudo mkdir -p /var/run/mysqld
andsudo chown mysql /var/run/mysqld
- After this, running
mysqld_safe
will run with the messageStarting mysqld daemon with databases from /var/lib/mysql
and then hang. And Ctrl+C doesn't get me out of that. - In a new terminal window i can now actually connect with
mysql -u root
and get themysql>
prompt. - I can set a new password with
use mysql; update user set authentication_string=password('0000') where user='root';flush privileges;
which will tell me it successfully updated the row with the messageRows matched: 1 Changed: 1 Warnings: 1
- The warning only states:
'PASSWORD' is deprecated and will be removed in a future release.
- And after all this, i'm back at square one: The process still hangs, so i have to reboot because
killall mysqld_safe
saysno process found
. After rebooting and entering my new password0000
, i will get access denied.
- First i run
The system is Linux 4.15.0-48-generic #51-Ubuntu SMP
.
The mysqladmin solution
If i run mysqladmin -u root password '0000'
(without sudo
), i get:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost''
If i run it with sudo
, i get:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
This last one doesn't really tell me anything in regards of whether the password change happened or not; has it been refused or not (since it's a warning, not an error, i would assume it should go through), but in either case, trying to connect with 0000
still says "access denied".
Any advice on how to fix this is greatly appreciated.