不重启Mysql修改root密码的方法
一、一般忘记密码的解决办法,需要重启Mysql
1、skip-grant-tables
我们常用的方法是使用skip-grant-tables选项,mysqld server启动之后并不使用权限系统(privilege system)。用户不需要任何账号、不受任何限制的访问数据库中所有数据。为了安全起见,通常加上 skip-working ,mysqld不侦听任何TCP/IP连接请求。操作过程如下,
1)修改my.f配置文件,在mysqld选项中添加skip-grant-tables和skip-working。
2)再重启mysqld server。
3)通过sql语句修改mysql.user表中存储密码。执行flush privileges,重新启用mysql权限系统。
FLUSH PRIVILEGES;
4)删除或者注释配置文件中skip-grant-tables和skip-working的参数选项。如果使用skip-working,则需要重启mysqld。因为skip-working不是系统变量,只是mysqld的参数选项,而不能通过系统变量动态进行设置。如果没有适用skip-working,只需要执行flush privileges就可以使权限系统重新生效。
2. --init-file
mysqld_safe可以使–init-file参数选项来执行重新设定密码的sql语句。
1)新建一个初始化文件,如/tmp/initfile,文件内容为上面修改密码的sql语句。
FLUSH PRIVILEGES;
2)关闭mysqld服务进程。
3)使用mysqld_safe启动mysqld;
上面的两种方法是在忘记root密码情况下重新设置密码的方法,可以发现都需要重启mysqld服务。很多人都是使用第一种进行重置root密码,比较推荐的做法反而是第二种,即安全有快捷简单。
二、不重启mysqld的方法
1、得有一个可以拥有修改权限的mysql数据库账号,当前的mysql实例账号(较低权限的账号,比如可以修改test数据库)或者其他相同版本实例的账号。把data/mysql目录狼蚁网站SEO优化的user表相关的文件复制到data/test目录狼蚁网站SEO优化。
[root@localhost mysql]# cp mysql/user. test/
[root@localhost mysql]# chown mysql.mysql test/user.
2、使用另一个较低权限的账号链接数据库,设置test数据库中的user存储的密码数据。
[root@localhost mysql]# mysql -utest -p12345
Wele to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.5.25a-log Source distribution
Copyright (c) 2000, 2011, 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> use test
Reading table information for pletion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password('yayun') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5 Changed: 0 Warnings: 0
mysql>
3、把修改后的user.MYD和user.MYI复制到mysql目录下,记得备份之前的文件。
mv mysql/user.MYD mysql/user.MYD.bak
mv mysql/user.MYI mysql/user.MYI.bak
cp test/user.MY mysql/
chown mysql.mysql mysql/user.
4、查找mysql进程号,并且发送SIGHUP信号,重新加载权限表。
[root@localhost mysql]# pgrep -n mysql
2184
[root@localhost mysql]#
[root@localhost mysql]# kill -SIGHUP 2184
5、登陆测试
[root@localhost mysql]# mysql -uroot -pyayun
Wele to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.5.25a-log Source distribution
Copyright (c) 2000, 2011, 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>
编程语言
- 甘肃哪有关键词排名优化购买方式有哪些
- 甘肃SEO如何做网站优化
- 河南seo关键词优化怎么做电话营销
- 北京SEO优化如何做QQ群营销
- 来宾百度关键词排名:提升您网站曝光率的关键
- 卢龙关键词优化:提升您网站排名的策略与技巧
- 山东网站优化的注意事项有哪些
- 四川整站优化怎样提升在搜索引擎中的排名
- 疏附整站优化:提升网站性能与用户体验的全新
- 海南seo主要做什么工作售后服务要做到哪些
- 荣昌百度网站优化:提升您网站的搜索引擎排名
- 河北seo网站排名关键词优化如何做SEO
- 江西优化关键词排名推广售后保障一般有哪些
- 古浪SEO优化:提升你的网站可见性
- 西藏网站排名优化怎么把网站排名在百度首页
- 如何提升阳东百度快照排名:详尽指南