Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access denied while running Mysql for the first time on Centos

Tags:

mysql

root

centos

I just installed Mysql for the first time on a CentOS machine using yum. The installation had no errors. Then I followed those steps:

$ sudo /sbin/service mysqld start --skip-grant-tables --skip-networking

$ sudo /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Enter current password for root (enter for none): 

It can be seen that even after first installation there is issue in logging in to the DB. I have even tried all command in sudo, but the error is still there. I can't even figure out how to reconfigure MySQL. I halso have installed-removed mysql 3 times.

How can I solve this issue?

like image 416
Animesh Pandey Avatar asked May 19 '15 19:05

Animesh Pandey


People also ask

How do I fix access denied in MySQL?

To resolve the error, you must create a user with the following command: mysql> GRANT ALL ON *. * to user_name@localhost IDENTIFIED BY 'password'; Replace user_name with the user's username and password with the user's password.

How do I fix MySQL error Access denied for user root localhost?

Use the ALTER USER command and change the authentication method to log into MySQL as root: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password'; This command changes the password for the user root and sets the authentication method to mysql_native_password.

How do I enable root access in MySQL?

Configuring a default root password for MySQL/MariaDB Use the following procedure to set a root password. To change the root password, type the following at the MySQL/MariaDB command prompt: ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP4ssw0rd'; flush privileges; exit; Store the new password in a secure location.

How do I fix error 1045 28000 Access denied?

Set root user password Login as user root with blank password >mysql -u root mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc';


2 Answers

Just for anyone who has this issue on MySQL 5.7. or higher.

MySQL v 5.7 or higher generates a temporary random password after installation and stored that in mysql error log file, located at /var/log/mysqld.log for an installation by the MySQL Yum repository on CentOS 7.

use below command to see the password:

sudo grep 'temporary password' /var/log/mysqld.log

Ref: MySQL 5.7.7 - Centos 7 el7 - Access denied

EDIT1

For anyone that has different error log file, you can find it using @Drew's answer here below.

like image 145
SubRed Avatar answered Oct 02 '22 17:10

SubRed


Maybe you already setted it at some point. You can try this:

yum remove mysql-server
rm -rf /var/lib/mysql
yum install mysql-server
systemctl start mysqld.service
/usr/bin/mysql_secure_installation

Anyway, I think this question should be in ServerFault.

like image 38
Fernando Garcia Avatar answered Oct 02 '22 15:10

Fernando Garcia