Selasa, 16 Oktober 2018

How to reset mysql 5.1 root user from command line centos 6

  Tidak ada komentar
MySQL version
[[email protected] ~]# mysql -V
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
[[email protected] ~]#
Check status and stop mysql service
[[email protected] ~]# service mysqld status
mysqld (pid  96638) is running...
[[email protected] ~]#
[[email protected] ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]
[[email protected] ~]# service mysqld status
mysqld is stopped
[[email protected] ~]#
Start mysql service with skipping grant table
[[email protected] ~]# sudo mysqld_safe --skip-grant-tables &
[1] 45816
[[email protected] ~]# 181016 17:40:50 mysqld_safe Logging to '/var/log/mysqld.log'.
181016 17:40:50 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[[email protected] ~]#
Enter to mysql and change the root password
[[email protected] ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> update mysql.user set authentication_string=password('NewPassword') where user='root';
ERROR 1054 (42S22): Unknown column 'authentication_string' in 'field list'
mysql> update mysql.user set password=password('NewPassword') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye
[[email protected] ~]#
Restart mysql service
[[email protected] ~]$ sudo service mysqld restart
[sudo] password for msteam:
2018-09-24T10:29:47.899437Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[1]+  Done                    sudo mysqld_safe --skip-grant-tables
[[email protected] ~]$

Trying login to mysql without password to make sure our grant table not skipping
[[email protected] ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[[email protected] ~]#
Enter to mysql using new root password that we set before
[[email protected] ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit
Bye
[[email protected] ~]#

Tidak ada komentar :

Posting Komentar