1

I read and followed the process on https://websiteforstudents.com/install-mysql-8-0-on-ubuntu-16-04-17-10-18-04/ to install mySql on my ubuntu virtual machine. Everyhting run just absolutely fine. But when i try to

sudo mysql -u root -p

on the terminal it gives error like

Access denied for user 'root'@'localhost' (using password: YES)

I am not able to even reset my password as nothing is opening. Is there any way to reset password (if that's the problem) from the terminal.

UPDATE

I read on How to find out the MySQL root password the way but after the first

sudo service mysql stop

when i try to

sudo mysqld_safe --skip-grant-tables

It gives me error like

2018-06-27T06:24:15.801227Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-06-27T06:24:15.802880Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

I repeated the whole download process still the error seems to persist. Moreover though i am the admin using

mkdir -p /var/run/mysqld

tells me that i dont have the permission to do the creation

mkdir -p /var/run/mysqld
rahul yadav
  • 432
  • 3
  • 20

2 Answers2

2

Here is the step that will help you to reset the password for root user.

Here I am using "mysqld", in your system you might need to use "mysql"

Stop the Mysql Service and start in safe mode

service mysqld stop
mysqld_safe --skip-grant-tables &

If above mysqld_safe --skip-grant-tables gives error then:

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

Connect to mysql without password

mysql

Now reset the root password and exit

One of below will work for your mysql: (either with password or authentication_string column)

UPDATE mysql.user SET password=PASSWORD('NEW-PASSWORD') WHERE User='root';
UPDATE mysql.user SET authentication_string=PASSWORD('NEW-PASSWORD') WHERE User='root';

FLUSH PRIVILEGES;
exit;

Shutdown the mysql safe mode service

mysqladmin -u root -p shutdown

Start the mysql service normally

service mysqld start

Now login with new password to mysql with new password.

mysql -uroot -p
Vivek
  • 783
  • 5
  • 11
  • If it gives the error while starting in safe mode, you need to create the directory and give the permission as : sudo mkdir -p /var/run/mysqld sudo chown mysql:mysql /var/run/mysqld – Vivek Jun 27 '18 at 06:57
1

I had the same problem with the MySQL root user. Try logging in as root on the linux maschine an login from there to the mysql as root:

sudo su # or just su, if you don't have sudo
mysql # normally, no further parameter are needed. If this is not working try mysql -u root
mscho
  • 860
  • 7
  • 16
  • Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) Gives this error @mscho – rahul yadav Jun 27 '18 at 06:49
  • Then most probably mysql is not started. Try `sudo service mysql start`. If is is still not starting, check the error logs. – mscho Jun 27 '18 at 07:15