0% found this document useful (0 votes)
190 views

Centos - Change Mysql Root Password On Centos7 - Stack Overflow

1. The document discusses how to reset the root password for MySQL on CentOS 7. 2. The mysqld_safe command is no longer used to start MySQL; systemctl must be used instead. 3. To reset the root password, MySQL must be started with the --skip-grant-tables option, the password updated in the mysql.user table, and MySQL restarted normally.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
190 views

Centos - Change Mysql Root Password On Centos7 - Stack Overflow

1. The document discusses how to reset the root password for MySQL on CentOS 7. 2. The mysqld_safe command is no longer used to start MySQL; systemctl must be used instead. 3. To reset the root password, MySQL must be started with the --skip-grant-tables option, the password updated in the mysql.user table, and MySQL restarted normally.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

9/4/2018 centos - Change mysql root password on Centos7 - Stack Overflow

Change mysql root password on Centos7 Ask Question

I have installed mySQL on a Centos7 vm but I have problems logging in


with root. I tried logging in without password or tried any default ones (like
mysql, admin etc) I looked in the my.cnf file and there's no password. I
tried changing the password by stopping the service and restarting it with
mysqld_safe --skip-grant-tables & but I get that mysqld_safe:command not
found I have no idea what else to do. Any tips/ideas would be greatly
appreciated!

mysql centos

edited Jan 2 '17 at 18:08

asked Nov 3 '15 at 22:20


KeykoYume
526 2 8 22

You'll need to specify the full path to the command. If you don't know what that
is, find is your friend. The password will not be, should not be expressed in
my.cnf . – tadman Nov 3 '15 at 22:30

6 Answers

Join Stack Overflow to learn, share knowledge, and build your career.
This site uses cookies to deliverWhat version
our services of to
and mySQL arerelevant
show you you using? I''mjob
ads and using 5.7.10
listings. and had
By using the you acknowledge that you have read and understand our
our site,
same
Cookie Policy, Privacy Policy, and problem
our Terms with logging
of Service on of
. Your use asStack
root Overflow’s Products and Services, including the Stack Overflow Network, is subject to these
policies and terms. Email Sign Up OR SIGN IN WITH Google Facebook

https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7 1/8
9/4/2018 centos - Change mysql root password on Centos7 - Stack Overflow

There is 2 issues - why can't I log in as root to start with, and why can I not
use 'mysqld_safe` to start mySQL to reset the root password.

I have no answer to setting up the root password during installation, but


here's what you do to reset the root password

Edit the initial root password on install can be found by running

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

http://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html

1. systemd is now used to look after mySQL instead of mysqld_safe


(which is why you get the -bash: mysqld_safe: command not found error
- it's not installed)
2. The user table structure has changed.

So to reset the root password, you still start mySQL with --skip-grant-
tables options and update the user table, but how you do it has
changed.

1. Stop mysql:
systemctl stop mysqld

2. Set the mySQL environment option


Home systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

PUBLIC
3. Start mysql usig the options you just set
systemctl start mysqld
Stack Overflow
4. Login as root
Tags mysql -u root

5. Update the root user password with these mysql commands


Users
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPasswo
-> WHERE User = 'root' AND Host = 'localhost';
Jobs to learn, share knowledge, and build your career.
mysql> FLUSH PRIVILEGES;
This site uses cookies to deliver our services and to show you relevant ads and job listings. By using our site, you acknowledge that you have read and understand our
mysql> quit
, , and our . Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these
TEAMS
policies and terms. *** Edit *** OR SIGN IN WITH Google Facebook
Create Team As mentioned my shokulei in the comments, for 5.7.6 and later, you should u

https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7 2/8
9/4/2018 centos - Change mysql root password on Centos7 - Stack Overflow
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Or you'll get a warning

6. Stop mysql
systemctl stop mysqld

7. Unset the mySQL envitroment option so it starts normally next time


systemctl unset-environment MYSQLD_OPTS

8. Start mysql normally:


systemctl start mysqld

Try to login using your new password:


7. mysql -u root -p

Reference

As it says at http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html,

Note

As of MySQL 5.7.6, for MySQL installation using an RPM distribution,


server startup and shutdown is managed by systemd on several Linux
platforms. On these platforms, mysqld_safe is no longer installed
because it is unnecessary. For more information, see Section 2.5.10,
“Managing MySQL Server with systemd”.

Which takes you to http://dev.mysql.com/doc/refman/5.7/en/server-


management-using-systemd.html where it mentions the systemctl set-
environment MYSQLD_OPTS= towards the bottom of the page.

The password reset commands are at the bottom of


http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

edited Apr 3 at 14:43

to learn, share knowledge, and build your career.


This site uses cookies to deliver our services and to show you relevant ads and job listings. By using our site, you acknowledge that you have read and understand our
, , and our . Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these
policies and terms. OR SIGN IN WITHansweredGoogle
Dec 10 '15 at 17:20Facebook
Kevin Jones
https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7 3/8
9/4/2018 centos - Change mysql root password on Centos7 - Stack Overflow

2,377 1 11 12

I realise that this is pretty much the same answer as I gave here:
stackoverflow.com/questions/33374314/… but I'm not sure of what I should do if
it's essentially the same answer to 2 questions - give 2 answers or link from one
to the other? – Kevin Jones Dec 10 '15 at 17:23

This was an excellent answer where there really was no unified source for a
single answer in this exact situation. If only I had found this sooner, it would have
saved a few hours of work. Thank you. – Seth M. Larson May 2 '16 at 21:38

Thanks!grep 'temporary password' /var/log/mysqld.log – Mariano L Aug 16 '16 at


18:44

Thanks! this solution worked. My system didn't found the mysql_safe .. I don't
know why this is not marked as the solution. – Mariano L Nov 1 '16 at 19:38

1 Finally, I found clear working instructions. Everywhere mentioned mysqld_safe


command, but it is not found on my RedHat. – vogash Dec 25 '16 at 10:53

Use the below Steps to reset the password.

$ sudo systemctl start mysqld

Reset the MySql server root password.

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

to learn, share knowledge, and build your career.


This site uses cookies to deliverOutput Something
our services like-:you relevant ads and job listings. By using our site, you acknowledge that you have read and understand our
and to show
, , and our . Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these
10.744785Z 1 [Note] A temporary password is generated for root@localhost:
policies and terms. OR SIGN IN WITH Google Facebook

https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7 4/8
9/4/2018 centos - Change mysql root password on Centos7 - Stack Overflow

Use the above password during reset mysql_secure_installation process.

<pre>
$ sudo mysql_secure_installation
</pre>
Securing the MySQL server deployment.

Enter password for user root:

You have successfully reset the root password of MySql Server. Use the
below command to check the mysql server connecting or not.

$ mysql -u root -p

http://gotechnies.com/install-latest-mysql-5-7-rhelcentos-7/

answered Apr 15 '16 at 12:56


Arvind
71 1 1

As far as I can understand, this only works when the server is first created. All
that grep command does is find the temporary password, not set it. – Billy S May
7 at 20:21

Please stop all services MySQL with following command /etc/init.d/mysqld


stop After it use this

mysqld_safe --skip-grant-tables

its may work properly

answered Nov 5 '15 at 7:12


to learn, share knowledge, and build your career.
sumit Jaiswal
This site uses cookies to deliver our services and to show you relevant ads and job listings.
21By 1using our site, you acknowledge that you have read and understand our
, , and our . Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these
policies and terms. OR SIGN IN WITH Google Facebook

https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7 5/8
9/4/2018 centos - Change mysql root password on Centos7 - Stack Overflow

All,

Here a little bit twist with mysql-community-server 5.7 I share some steps,
how to reset mysql5.7 root password or set password. it will work centos7
and RHEL7 as well.

step1. 1st stop your databases

service mysqld stop

step2. 2nd modify /etc/my.cnf file add "skip-grant-tables"

vi /etc/my.cnf

[mysqld] skip-grant-tables

step3. 3rd start mysql

service mysqld start

step4. select mysql default database

mysql -u root

mysql>use mysql;

step4. set a new password

mysql> update user set authentication_string=PASSWORD("yourpassword")


where User='root' ;

step5 restart mysql database

service mysqld restart

mysql -u root -p

to learn, share knowledge, and build your career.


This site uses cookies to deliverenjoy :)
our services and to show you relevant ads and job listings. By using our site, you acknowledge that you have read and understand our
, , and our . Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these
policies and terms. OR SIGN IN WITHansweredGoogle
Oct 5 '17 at 15:00 Facebook
Narendra Kumar
https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7 6/8
9/4/2018 centos - Change mysql root password on Centos7 - Stack Overflow

31 1

I used the advice of Kevin Jones above with the following --skip-
networking change for slightly better security:

sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables --skip-netw

[user@machine ~]$ mysql -u root

Then when attempting to reset the password I received an error, but


googling elsewhere suggested I could simply forge ahead. The following
worked:

mysql> select user(), current_user();


+--------+-----------------------------------+
| user() | current_user() |
+--------+-----------------------------------+
| root@ | skip-grants user@skip-grants host |
+--------+-----------------------------------+
1 row in set (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'sup3rPw#'


ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-table
cannot execute this statement
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'sup3rPw#'


Query OK, 0 rows affected (0.08 sec)

mysql> exit
Bye
[user@machine ~]$ systemctl stop mysqld
[user@machine ~]$ sudo systemctl unset-environment MYSQLD_OPTS
[user@machine ~]$ systemctl start mysqld

to learn, share knowledge, and build your career.


This site uses cookies to deliverAt
ourthat pointand
services I was able you
to show to log in. ads and job listings. By using our site, you acknowledge that you have read and understand our
relevant
, , and our . Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these
edited Jun 22 at 13:10
policies and terms. OR SIGN IN WITH Google Facebook

https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7 7/8
9/4/2018 centos - Change mysql root password on Centos7 - Stack Overflow

answered Jun 22 at 12:53


user48918
141 1 4

For me work like this: 1. Stop mysql: systemctl stop mysqld

2. Set the mySQL environment option systemctl set-environment


MYSQLD_OPTS="--skip-grant-tables"
3. Start mysql usig the options you just set systemctl start mysqld
4. Login as root mysql -u root
5. After login I use FLUSH PRIVILEGES; tell the server to reload the
grant tables so that account-management statements work. If i don't
do that i receive this error trying to update the password: "Can't find
any matching row in the user table"

answered Jan 22 '17 at 10:08


Dragos Alexe
11 1

protected by Community ♦ 5 hours ago


Thank you for your interest in this question. Because it has attracted low-
quality or spam answers that had to be removed, posting an answer now
requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

to learn, share knowledge, and build your career.


This site uses cookies to deliver our services and to show you relevant ads and job listings. By using our site, you acknowledge that you have read and understand our
, , and our . Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these
policies and terms. OR SIGN IN WITH Google Facebook

https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7 8/8

You might also like