Initial authorization issue in mysql
Asked Answered
R

4

6

I tried multiple ways to install mySql and then access the database on a fresh installation. OS is RHEL 7. package used is mysql-5.7.7-0.3.rc.el7.x86_64.rpm-bundle.tar

installation process: 
[root@host1 mysql]# rpm -ivh mysql-community-common-5.7.7-0.3.rc.el7.x86_64.rpm mysql-community-libs-5.7.7-0.3.rc.el7.x86_64.rpm mysql-community-client-5.7.7-0.3.rc.el7.x86_64.rpm mysql-community-server-5.7.7-0.3.rc.el7.x86_64.rpm
 Preparing...                          ################################# [100%]
 Updating / installing...
1:mysql-community-common-5.7.7-0.3.################################# [ 25%]
2:mysql-community-libs-5.7.7-0.3.rc################################# [ 50%]
3:mysql-community-client-5.7.7-0.3.################################# [ 75%]
4:mysql-community-server-5.7.7-0.3.################################# [100%]

then I start the server

 systemctl start mysqld

After this I try to access the server with no password for root. I get error as:

[root@host1 mysql]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

As I have not set any password, not very sure why this error comes. After this I tried various options and mone could help me.

option 1 : asks to make a file and change password by using an init file. I tried using that and got output as:

    [root@host1 mysql]# mysqld_safe --init-file=/home/me/mysql-init & [1]28469
    -bash: mysqld_safe: command not found

Option 2 : set the password using mysqladmin command

[root@host1 mysql]# /usr/bin/mysqladmin -u root password
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

Option 3 : using mysql_secure_installation

[root@host1 mysql]#  mysql_secure_installation

Securing the MySQL server deployment.

Enter password for root user:
Error: Access denied for user 'root'@'localhost' (using password: NO)

Option 4 : mysql -u root

[root@host1 mysql]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

and various others. Can you please suggest what can be issue behind this.

Rep answered 13/7, 2015 at 21:55 Comment(3)
What operating system. Oops rhelForbes
mysql -u root ( don't use the "-p") ?Licentiate
the same: [root@host1 mysql]# mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)Rep
F
8

For those ever in a pickle over this:

  1. Stop MySql server

  2. Create a text file onetime.sql that contains something like:

set password for 'root'@'localhost' = PASSWORD('password789');

Path that file so it is safe and other users can't get to it, perhaps /home/jason

  1. Start MySql server with --init-file option:

mysqld_safe --init-file=/home/jason/onetime.sql &

  1. Wait happily while password is changed. Wait won't be long.

  2. delete that file ... rm /home/jason/onetime.sql

  3. Stop MySql server

  4. Start MySql server normal way

Edit this may be necessary :

Once MySQL has stopped,

edit your /etc/my.cnf file to add the line

skip-grant-tables 

restart it

Connect to MySQL using the root user.

mysql -u root

Once logged in, you should see the following prompt:

mysql>

Enter the following commands:

mysql> use mysql;
mysql> UPDATE user SET password=PASSWORD("YOUR NEW PASSWORD HERE") WHERE User='root';
mysql> flush privileges;
mysql> quit

Now stop MySQL again:

service mysqld stop

If you edited your /etc/my.cnf file, delete the skip-grant-tables line.

Now restart MySQL and test your new login.

service mysqld restart

mysql -u root -p

Forbes answered 13/7, 2015 at 22:19 Comment(11)
thanks for your comment, but I tried this and that's my first option. I got error as "mysqld_safe : command not found"Rep
find / -name mysqld_safeForbes
It's not in your pathForbes
Ya I tried to find that earlier, no such file in whole system. Am I missing something while installation.Rep
I was googling around trying to find a conf setting but am on an Android kinda limited. Will keep lookingForbes
edit your /etc/my.cnf file to add the line "skip-grant-tables" did the thing. Thanks a lotRep
Seems that was not end of things, now i'm into the database, but when I run command UPDATE user SET password=PASSWORD("root") where User='root'; I get error as ERROR 1054 (42S22): Unknown column 'password' in 'field list'Rep
Did u do use mysql ? You need to get in that special db firstForbes
yes I did. I'm able to see columns of table user by select * from user. Also I dont see any column in the table user named password. Strange?Rep
Sorry check this out you are close dev.mysql.com/doc/refman/5.0/en/set-password.htmlForbes
Set password=password("fffff")Forbes
B
11

“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 6/7. use below command to see the password:

cat /var/log/mysqld.log |grep "temporary password"
Breechcloth answered 10/1, 2016 at 15:26 Comment(2)
perfect solution. I was using rhel7 and mysql 5.7.Moise
the temp password didnt work for me. Got the temp password and I used it and it says sorry try againBrotherton
F
8

For those ever in a pickle over this:

  1. Stop MySql server

  2. Create a text file onetime.sql that contains something like:

set password for 'root'@'localhost' = PASSWORD('password789');

Path that file so it is safe and other users can't get to it, perhaps /home/jason

  1. Start MySql server with --init-file option:

mysqld_safe --init-file=/home/jason/onetime.sql &

  1. Wait happily while password is changed. Wait won't be long.

  2. delete that file ... rm /home/jason/onetime.sql

  3. Stop MySql server

  4. Start MySql server normal way

Edit this may be necessary :

Once MySQL has stopped,

edit your /etc/my.cnf file to add the line

skip-grant-tables 

restart it

Connect to MySQL using the root user.

mysql -u root

Once logged in, you should see the following prompt:

mysql>

Enter the following commands:

mysql> use mysql;
mysql> UPDATE user SET password=PASSWORD("YOUR NEW PASSWORD HERE") WHERE User='root';
mysql> flush privileges;
mysql> quit

Now stop MySQL again:

service mysqld stop

If you edited your /etc/my.cnf file, delete the skip-grant-tables line.

Now restart MySQL and test your new login.

service mysqld restart

mysql -u root -p

Forbes answered 13/7, 2015 at 22:19 Comment(11)
thanks for your comment, but I tried this and that's my first option. I got error as "mysqld_safe : command not found"Rep
find / -name mysqld_safeForbes
It's not in your pathForbes
Ya I tried to find that earlier, no such file in whole system. Am I missing something while installation.Rep
I was googling around trying to find a conf setting but am on an Android kinda limited. Will keep lookingForbes
edit your /etc/my.cnf file to add the line "skip-grant-tables" did the thing. Thanks a lotRep
Seems that was not end of things, now i'm into the database, but when I run command UPDATE user SET password=PASSWORD("root") where User='root'; I get error as ERROR 1054 (42S22): Unknown column 'password' in 'field list'Rep
Did u do use mysql ? You need to get in that special db firstForbes
yes I did. I'm able to see columns of table user by select * from user. Also I dont see any column in the table user named password. Strange?Rep
Sorry check this out you are close dev.mysql.com/doc/refman/5.0/en/set-password.htmlForbes
Set password=password("fffff")Forbes
A
5

Just do it:

cat /var/log/mysqld.log |grep "temporary password"

[Note] A temporary password is generated for root@localhost: dI&2-&FteI8a

sudo mysql_secure_installation
Securing the MySQL server deployment. Enter password for user root: > type here temporary password
The existing password for the user account root has expired. Please set a new password.
New password: > type here your new password  
Re-enter new password:

credits to user .pss

Actuate answered 15/12, 2016 at 16:50 Comment(2)
This was the response that led me to solution. The others were only partial solutions.Brotherton
This solution worked for me too for finding the default root password set by the MySQL NDB Cluster 7.6.7.Micropaleontology
N
-1

For those getting an error that column password doesn't exist do the following:

mysql> use mysql;
mysql> UPDATE user SET authentication_string=PASSWORD("YOUR NEW PASSWORD HERE") WHERE User='root';
mysql> flush privileges;
mysql> quit
Northward answered 4/12, 2016 at 7:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.