Professional Documents
Culture Documents
173780 人看了这个视频
播放列表
工具/原料
Windows 10 x64
mysql-5.7.19-winx64
方法/步骤
1. 1
如果不是以管理员身份运行 cmd 执行命令 net stop mysql 会报“发生系统错误 5 拒绝访问”
2. 2
重新以管理员身份运行 cmd,输入 net stop mysql
停止 MySQL 服务
3. 3
打开一个 cmd 窗口输入 mysqld --skip-grant-tables,注意这个 cmd 命令窗口不要关闭
4. 4
重新打开一个 cmd 窗口,运行下面命令
C:\Users\Administrator>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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
Database changed
mysql> update user set authentication_string=password('123456') where user='root';
Query OK, 0 rows affected, 1 warning (0.06 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql>
将 mysql 的 root 密码重置为 123456
5. 5
继续以管理员身份运行 cmd,输入 net start mysql
启动 MySQL 服务
6. 6
以重置后的 root 密码登录测试,如下图
mysql -uroot -p123456
END
linux 下 mysql 忘记密码怎么办
前言
修改密码
//关闭服务
[root@mytestlnx02 ~]# service mysql stop
[root@mytestlnx02 ~]#
2. 修改 mysql 的配置文件 my.cnf
my.cnf 配置文件的位置,一般在/etc/my.cnf,有些版本在/etc/mysql/my.cnf
在配置文件中,增加 2 行代码
[mysqld]
skip-grant-tables
作用是登录 mysql 的时候跳过密码验证
mysql>
3. 修改密码
连接 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
mysql> update mysql.user set authentication_string=password('root_password') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> exit
4. 重启 mysql 服务
先将之前加在配置文件里面的 2 句代码注释或删除掉,然后重启 mysql 服务,就可以使用刚刚设置的密码登录了。
p.s.
执行修改密码的命令一直报错
查看初始密码
[root@VM_0_8_centos ~]# grep 'temporary password' /var/log/mysqld.log
2018-09-26T04:25:54.927944Z 5 [Note] [MY-010454] [Server] A temporary password is generated fo
r root@localhost: DN34N/=?aIfZ
可以看到初始密码为 DN34N/=?aIfZ
使用初始密码登录
[root@VM_0_8_centos ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
修改密码
mysql> exit
Bye
重启服务就生效了
[root@VM_0_8_centos ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
[root@VM_0_8_centos ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service