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:
mysql -u root -p
will ask me for my password, and after i enter it, it will complain with ERROR 1698 (28000): Access denied for user 'root'@'localhost'
mysql -u root
(no password), it will say ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
mysqld_safe --skip-grant-tables
, then i run across some hiccups along the way:
sudo service mysql stop
sudo mysql_safe --skip-grant-tables
will say mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
sudo mkdir -p /var/run/mysqld
and sudo chown mysql /var/run/mysqld
mysqld_safe
will run with the message Starting mysqld daemon with databases from /var/lib/mysql
and then hang. And Ctrl+C doesn't get me out of that. mysql -u root
and get the mysql>
prompt.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 message Rows matched: 1 Changed: 1 Warnings: 1
'PASSWORD' is deprecated and will be removed in a future release.
killall mysqld_safe
says no process found
. After rebooting and entering my new password 0000
, i will get access denied. The system is Linux 4.15.0-48-generic #51-Ubuntu SMP
.
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.
I didn't quite solve the problems with mysql
directly; However for myself, the acceptable solution was switching to a different database software, but it's still a MySQL system, and it got me up and running. So if anyone gets stuck on existing solutions not working like i did, maybe this comes in handy to get you on the road and finally writing code again.
What i did was:
mysql
off my system /etc/mysql
and /var/lib/mysql
(don't know if this step was necessary)apt clean
, apt autoremove
, apt update
mariadb
mysqld_safe --skip-grant-tables
method to create a new user with all privileges, since connecting with root
always kept failing PHP + MariaDB now working again.