平台:win7
1、打开cmd窗口,进入 MySQL的安装目录。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMjEzOTIxOS02MDQ1MTg4MzEucG5n.png)
2、停止MySQL的服务。已经停止了。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMTk0NTY1MC0xMjMzNDY4NzY2LnBuZw==.png)
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMjAwNTg4NC0zODYyMjYxMC5wbmc=.png)
右键MySQL,看到启动是可点击的,证明MySQL服务已停止运行。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIxMDIxMDI1ODUxNi05MjI0NTU1OTIucG5n.png)
3.将root用户对数据库操作的的权限授予给别的用户。
输入 mysqld --skip-grant-tables 回车
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMjIwNzI2Mi0xNjMxMjU5MTc2LnBuZw==.png)
4、重新打开一个窗口,进入bin目录,输入mysql,然后再输入use mysql,如下图所示:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMjcxMzQwMS0xNTM0MjcwODQyLnBuZw==.png)
5、修改数据库连接密码,命令
update user set password=password("123456") where user="root";
注:这里的“123456”为设置的新密码。注意语句后面的“;”,别漏。如果不写“;”,回车之后输入“\g”,效果一样。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMjkzNjg5NS0yMDYxNDY2ODEyLnBuZw==.png)
出现错误:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMjc0Mjk2Ny0yNDc1NDIxMTEucG5n.png)
正确的应该是:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMjgwMjE5NC0zNDM2ODI3MDMucG5n.png)
查找解决方案:说是mysql5.7以上没有password这个字段,变成了authentication_string,然后重新设置新密码成功。
参考链接:https://www.techietown.info/2017/04/resolved-error-unknown-column-password-field-list/
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMjgzMzM2Mi0yNTgzNjMyMDUucG5n.png)
6、重新加载一下权限,将设置了密码的用户root的权限信息从内存中写入数据库。输入命令flush privileges;,英文分号“;”不可省略。如果不写“;”,回车之后输入“\g”,效果一样。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMjkzNjg5NS0yMDYxNDY2ODEyLnBuZw==.png)
7、退出 mysql 。输入quit。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMjk1Mzg3MS03MjczNTk3NzMucG5n.png)
8、修改 root 密码后,需要执行下面的语句和新修改的密码。另开一个cmd窗口,执行以下命令,然后提示输入密码:输入4中设置的密码。
mysqladmin -u root -p shutdown
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMzAxMzI3MS05NzMzNjIzNDMucG5n.png)
9、开启数据库服务。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMzA0NDQxNS0xNjY0MjY1MDA4LnBuZw==.png)
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMzExMjc2My0yMDY2MzU4OTkxLnBuZw==.png)
10、验证是否设置成功。另开cmd,进入到mysql的bin目录下,输入mysql –u root –p,回车之后提示输入密码,然后显示如下。连接成功。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTIyNzQ1NC8yMDE4MTIvMTIyNzQ1NC0yMDE4MTIwOTIwMzEyNzE0MS02NTgyMzc1MTgucG5n.png) |