下午把数据库关闭了,准备修改通过skip-granted-tables修改下root的密码,结果关闭之后,重启不成功。
[root@iZ2zehmkcpexiu333gfymtZ ~]# service mysqld start
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
mysql关闭之后无法正常启动,提示启动失败。
查看mysql启动日志:
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
提示不能启动服务,不能创建PID文件,权限不足
- Can't create/write to file '/var/run/mysqld/mysqld.pid' 提示不能创建pid文件,目录为 /var/run/mysqld/ 看了下目录权限为nobody
而mysql使用的是mysql用户运行的,把权限修改 chmod 777 /var/run/mysqld -R
#############################################################################################
重置密码步骤:
1、先查看mysql是否启动,找到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、关闭mysqld
- [root@iZ2zehmkcpexiu333gfymtZ ~]# service mysqld stop
- Stopping mysqld: [ OK ]
3、 -–skip-grant-tables 跳过授权表启动mysql , 这个地方重启mysql的时候 需要注意,这个时候mysql只能在 本服务器进行连接不需要用户名密码,直接mysql 就可以进行命令行,可以在这个命令之后在价格 & 表示这个这个进程挂到后台运行
- [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<span style="color:#ff6666;"> --skip-grant-tables </span>
- 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、进入mysql,直接就可以操作了
- [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、查询下user表,其中Host对应的 % 表示允许任意主机访问,如果要限制具体的ip访问,修改为指定的ip就行
- 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)
- mysql> update user set Password=password('123456');
- Query OK, 0 rows affected (0.00 sec)
- Rows matched: 1 Changed: 0 Warnings: 0
- mysql> <span style="color:#ff0000;">flush privileges;</span>
- Query OK, 0 rows affected (0.00 sec)
- mysql>
7、关闭mysql,重新启动mysql
- [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 ~]#