mysql退出root_mysql重置root用户密码

1、连上mysql所在机器

2、停止数据库

[root@lin-21-36-24 ~]# /etc/init.d/mysqld stop

Shutting down MySQL....2019-03-21T11:44:27.298768Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

SUCCESS!

3、进入无密码模式

[root@lin-21-36-24 ~]# cd /usr/local/mysql/bin

[root@lin-21-36-24 bin]# sudo su

[root@lin-21-36-24 bin]# ./mysqld_safe --skip-grant-tables &

4、重新开启一个终端窗口

5、在新开终端窗口配置短命令

[root@lin-21-36-24 ~]# alias mysql=/usr/local/mysql/bin/mysql

6、进入mysql命令模式

[root@lin-21-36-24 ~]# mysql

7、进入mysql数据库

mysql> use mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

8、获取权限

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

9、重置root用户密码

mysql> update user set authentication_string=password('root') where user='root';

Query OK, 0 rows affected, 1 warning (0.00 sec)

Rows matched: 2  Changed: 0  Warnings: 1

10、退出mysql模式

mysql> exit

11、停止mysql

[root@lin-21-36-24 ~]# /etc/init.d/mysqld stop

Shutting down MySQL.... SUCCESS!

12、启动mysql

[root@lin-21-36-24 ~]# service mysqld start

Starting MySQL. SUCCESS!

PS :如果遇到改完密码后连接被拒

7675ef25af9e

解决方案:

1、在/etc/my.cnf添加配置项

[mysqld]---在这个下面添加skip-grant-tables

7675ef25af9e

2、停止mysql

/etc/init.d/mysqld stop

3、重启mysql

service mysqld start

1)查看进程被那谁占用然后kill掉ps aux |grep mysql*

[root@lin-19-73-195 ~]# ps aux |grep mysql*

mysql    3221  0.7  0.1 1028464 179972 pts/1  Sl+  10:55  0:00 mysqld stop

root      3268  0.0  0.0  12132  656 pts/0    S+  10:57  0:00 grep mysql*

[root@lin-19-73-195 ~]# kill -9 3221

-bash: kill: (3221) - No such process

[root@lin-19-73-195 ~]# ps aux |grep mysql*

root      3270  0.0  0.0  12132  656 pts/0    S+  10:57  0:00 grep mysql*

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值