Reputation: 6018
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?
Upvotes: 7
Views: 32219
Reputation: 21
you misunderstood. Because of you havn't set the password yet. you should just enter for none.
In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here.
Upvotes: 1
Reputation: 3187
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.
Upvotes: 32
Reputation: 24949
A visual of the temporary root password written to the Error Log file
Not that one can exactly rifle off the command
select @@log_error;
to find the location of the Error Log file without logging in (a which came first, the chicken or the egg predicament).
But the typical locations are
C:\ProgramData\MySQL\MySQL Server 5.7\Data\
(for Windows. You must unhide the C:\ProgramData dir)
and
mysql> select @@log_error;
+---------------------+
| @@log_error |
+---------------------+
| /var/log/mysqld.log |
+---------------------+
(for Linux)
Upvotes: 3
Reputation: 21
sudo mysql_secure_installation
pass
Upvotes: 1
Reputation: 1969
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.
Upvotes: 6