Access denied when starting Mysql for the first time on Centos

I just installed Mysql for the first time on a CentOS machine using yum

. The installation had no errors. Then I followed these 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): 

      

You can see that even after the first installation, there is a problem entering the database. I even tried the whole command in sudo

, but the error still exists. I can't even figure out how to reconfigure MySQL. I have halso installed remote mysql 3 times.

How can I solve this problem?

+3


source to share


5 answers


You may have already installed 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 on ServerFault.

+2


source


Just for anyone who has this problem in MySQL 5.7. or higher.

MySQL v 5.7 or later generates a temporary random password after installation and is saved in the mysql error log file located in /var/log/mysqld.log

the MySQL Yum installation repository on CentOS 7.

use below command to see password:

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

      



Ref: MySQL 5.7.7 - Centos 7 el7 - Access Denied

EDIT1

For those with a different error log file, you can find it using @ Drew's answer here below.

+27


source


Temporary root visual password written to the error log file

enter image description here

Can't squeeze out a team

select @@log_error;

      

to find the location of the error log file without logging in (and that was the first, chicken or egg fix).

But typical locations

C:\ProgramData\MySQL\MySQL Server 5.7\Data\

      

(for Windows. You should map the directory C: \ ProgramData)

and

mysql> select @@log_error;
+---------------------+
| @@log_error         |
+---------------------+
| /var/log/mysqld.log |
+---------------------+

      

(for Linux)

+3


source


you misunderstood. Because of this, you haven't set a password yet. you should just enter the value none.

To log into MariaDB to secure it, we need the current password for the root user. If you just installed MariaDB and you haven't set a root password yet, the password will be blank, so you should just click here.

0


source


  • sudo mysql_secure_installation

  • When it asks for a password type pass

  • Follow the instructions to change the root password
-1


source







All Articles