解决mysql 数据库连接密码
用到的命令:
bin>net stop mysql
bin>mysqld --skip-grant-tables
bin>mysql
mysql>use mysql
mysql>update user set password=password("123456") where user="root";
mysql>flush privileges;
mysql>quit
bin>mysqladmin -u root -p shutdown
bin>net start mysql
- 进入 mysql 的 bin 目录下,打开 cmd ,关闭 mysql 数据库。
- 输入
mysqld --skip-grant-tables
回车。
(–skip-grant-tables 的意思是启动 MySQL 服务的时候跳过权限表认证)
注意:这时候,刚刚打开的 cmd 窗口已经不能使用了。重新再 bin 目录下打开一个新的 cmd 窗口进行下面的操作
- 重新打开一个 cmd 窗口。输入
mysql
回车
- 进mysql数据库
use mysql
- 修改数据库连接密码:
update user set password=password("123456") where user="root";
注释:这里的“123456”为新密码,root是用户名,请根据自己的需求,输入新的密码。注意语句后面的“;”不能遗漏。
- 刷新权限(必须步骤)
flush privileges;
- 退出 mysql
- 修改 root 密码后,需要执行下面的语句和新修改的密码。不然开启 mysql 时会出错。
mysqladmin -u root -p shutdown
- 重启 mysql