linux下mysql 忘记密码

[root@localhost bin]# service mysql status
 SUCCESS! MySQL running (114177)

查看服务状态
service mysqld stop
[root@localhost etc]# vi m
machine-id                mailcap                   makedumpfile.conf.sample  maven/                    mke2fs.conf               modules-load.d/           mtab                      multipath/                my.cnf.d/                 
magic                     mail.rc                   man_db.conf               mime.types                modprobe.d/               motd                      mtools.conf               my.cnf                    
[root@localhost etc]# vi my.cnf
编辑配置文件  找到 [mysqld]这个模块:

添加  skip-grant-tables 
service mysqld start
[root@localhost etc]# service mysql restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@localhost etc]# 
[root@localhost etc]# 
[root@localhost etc]# 
[root@localhost etc]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.41 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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 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
mysql> update user set password=password("julong") where user="root";
Query OK, 4 rows affected (0.08 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.08 sec)
[root@localhost etc]# killall mysqld
[root@localhost etc]# service mysql start
Starting MySQL. SUCCESS! 
再次登录就OK了 
有人说用window下得navicat连接需要授权 我没有首先直连OK  如果连不上 先关闭防火墙试试

你可能感兴趣的:(linux,mysql)