MYSQL - root Password Forgot back

The database is shut down in the afternoon, ready to modify modify the root through skip-granted-tables password, and then shut down, restart unsuccessful.

[root@iZ2zehmkcpexiu333gfymtZ ~]# service mysqld start

MySQL Daemon failed to start.

Starting mysqld:                                           [FAILED]

mysql After closing does not start normally, suggesting that failed to start.

View mysql start the log:

tail -20  /var/log/mysqld.log

180516 18:33:07 [ERROR] /usr/libexec/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13)
180516 18:33:07 [ERROR] Can't start server: can't create PID file: Permission denied
180516 18:33:07 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
180516 18:33:20 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
180516 18:33:20  InnoDB: Initializing buffer pool, size = 8.0M
180516 18:33:20  InnoDB: Completed initialization of buffer pool
180516 18:33:20  InnoDB: Started; log sequence number 0 1455648
180516 18:33:20 [ERROR] /usr/libexec/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13)
180516 18:33:20 [ERROR] Can't start server: can't create PID file: Permission denied
180516 18:33:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

Tips can not start the service, you can not create PID file, insufficient permissions

Can't create/write to file '/var/run/mysqld/mysqld.pid' 提示不能创建pid文件,目录为 /var/run/mysqld/ 看了下目录权限为nobody 

And using the mysql mysql user runs, the rights to modify chmod 777 / var / run / mysqld -R

#############################################################################################

Reset Password steps:

    1, first check if mysql start, find the path to mysqld_safe

[root@iZ2zehmkcpexiu333gfymtZ ~]# ps -ef | grep mysqld
root      8702     1  0 18:35 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql     8804  8702  0 18:35 ?        00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root      9106  9069  0 18:45 pts/4    00:00:00 grep mysqld

 2, shut down mysqld
 

[root@iZ2zehmkcpexiu333gfymtZ ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]

 3, --skip-grant-tables to skip the grant tables start mysql, mysql restart when this place needs attention, this time can only be connected in this mysql server does not require a user name and password, you can directly mysql command line, you can after this command in price & means that the process linked to run in the background

[root@iZ2zehmkcpexiu333gfymtZ ~]# /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql --skip-grant-tables 
180516 18:47:14 mysqld_safe Logging to '/var/log/mysqld.log'.
180516 18:47:14 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

4, enter mysql, can be directly manipulated

[root@iZ2zehmkcpexiu333gfymtZ ~]# 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> 

5, the user query tables, wherein% represents the corresponding Host allows any host to access, to limit access to specific ip, ip modify the specified line

mysql> select * from user \G;
*************************** 1. row ***************************
                 Host: %
                 User: root
             Password: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
          Select_priv: Y
          Insert_priv: Y
          Update_priv: Y
          Delete_priv: Y
          Create_priv: Y
            Drop_priv: Y
          Reload_priv: Y
        Shutdown_priv: Y
         Process_priv: Y
            File_priv: Y
           Grant_priv: Y
      References_priv: Y
           Index_priv: Y
           Alter_priv: Y
         Show_db_priv: Y
           Super_priv: Y
Create_tmp_table_priv: Y
     Lock_tables_priv: Y
         Execute_priv: Y
      Repl_slave_priv: Y
     Repl_client_priv: Y
     Create_view_priv: Y
       Show_view_priv: Y
  Create_routine_priv: Y
   Alter_routine_priv: Y
     Create_user_priv: Y
           Event_priv: Y
         Trigger_priv: Y
             ssl_type: 
           ssl_cipher: 
          x509_issuer: 
         x509_subject: 
        max_questions: 0
          max_updates: 0
      max_connections: 0
 max_user_connections: 0
1 row in set (0.00 sec)

6, modify the root password, refresh permission, change your password MYSQL different versions in different ways (ps: remember to refresh every time you modify the permissions)

mysql> update user set Password=password('123456');
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0
 
mysql> flush  privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> 

7, close mysql, mysql restart

[root@iZ2zehmkcpexiu333gfymtZ ~]# ps -ef | grep mysql
root      9314  9052  0 18:47 pts/3    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql --skip-grant-tables
mysql     9416  9314  0 18:47 pts/3    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --skip-grant-tables --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root      9798  9069  0 19:02 pts/4    00:00:00 grep mysql
[root@iZ2zehmkcpexiu333gfymtZ ~]# killall mysqld_safe 
[root@iZ2zehmkcpexiu333gfymtZ ~]# kill -7 9314
[root@iZ2zehmkcpexiu333gfymtZ ~]# service mysqld start
Starting mysqld:                                           [  OK  ]
[root@iZ2zehmkcpexiu333gfymtZ ~]# 

 

Guess you like

Origin blog.csdn.net/lr199966/article/details/93756443