Selasa, 16 Oktober 2018

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

  Tidak ada komentar
MySQL version
[root@localhost ~]# mysql -V
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
[root@localhost ~]#
Check status and stop mysql service
[root@localhost ~]# service mysqld status
mysqld (pid  96638) is running...
[root@localhost ~]#
[root@localhost ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]
[root@localhost ~]# service mysqld status
mysqld is stopped
[root@localhost ~]#
Start mysql service with skipping grant table
[root@localhost ~]# sudo mysqld_safe --skip-grant-tables &
[1] 45816
[root@localhost ~]# 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

[root@localhost ~]#
Enter to mysql and change the root password
[root@localhost ~]# 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
[root@localhost ~]#
Restart mysql service
[msteam@dbbackup ~]$ 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
[msteam@dbbackup ~]$

Trying login to mysql without password to make sure our grant table not skipping
[root@localhost ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]#
Enter to mysql using new root password that we set before
[root@localhost ~]# 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
[root@localhost ~]#

Tidak ada komentar :

Posting Komentar