Reputation: 31
While connecting to mysql through 'root' user, I am getting the mentioned error. Commands tried:
mysql (as by default it takes root user)
mysql -u root -p
I Tried putting the root credentials in "/etc/my.cnf" file, but no luck.
Please help.
Upvotes: 2
Views: 26645
Reputation: 77
Note: All credit to this answer goes to Netaji and you can found his answer Here
my problem was solved in below way.
When I was entered below command then I will get an error. sudo mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).
To resolve this follow below steps.
enter command
sudo mysqld_safe --skip-grant-tables & [4] 21878
Then the below error occurred.
2018-12-17T06:43:33.106111Z mysqld_safe Logging to syslog.
2018-12-17T06:43:33.108971Z mysqld_safe Logging to '/var/log/mysql/error.log'.
/usr/bin/mysqld_safe: 152: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied
2018-12-17T06:43:33.111388Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
/usr/bin/mysqld_safe: 152: /usr/bin/mysqld_safe: cannot create /var/log/mysql//error.log: Permission denied
^C
[4] Exit 1 mysqld_safe --skip-grant-tables
To resolve this error, then follow below lines.
i) systemctl stop mysql
2018-12-17T06:48:42.971692Z mysqld_safe Logging to syslog.
2018-12-17T06:48:42.974451Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-12-17T06:48:42.976653Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
ii) sudo mkdir -p /var/run/mysqld
iii) sudo chown mysql:mysql /var/run/mysqld
iv)sudo mysqld_safe --skip-grant-tables &
[5] 24203
2018-12-17T06:50:39.135292Z mysqld_safe Logging to syslog.
2018-12-17T06:50:39.137938Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-12-17T06:50:39.152966Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
v) Then connect mysql -u root.
then MySQL prompt will appear. then after set your password.
vi) FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
vi) systemctl stop mysql
vi) After that loing in below way.
`mysql -u root -p`
Upvotes: 3
Reputation:
First: You don't want to put your credentials in /etc/my.cnf
but in ~/.my.cnf
(mind the leading dot). The contents of .my.cnf
should look like this
[client]
user=USERNAME
pass=PASSWORD
If your password is correct, you should be able to login with just mysql
without any options.
If that doesn't work and you are not able to login with
mysql -u root -pMYPASS
(mind the missing space between -p
and the actual password), then you may have to reset the password.
Upvotes: 0
Reputation: 231
IMHO, you didn't describe you situation clearly. Is your mysql a new install, reinstall or upgrade? Or any operation you performed on root user? What is your mysql version? ...
Actually, there are many questions similar to your cases, have your tired their solution?
Upvotes: 0
Reputation: 862
You have to reset your mysql root password
please follow these instructions : https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
Upvotes: 0