- 在windows下:
- 打开命令行窗口,停止mysql服务:Net stop mysql
- 到mysql的安装路径启动mysql,在bin目录下使用mysqld-nt.exe启动,在命令行窗口执行:mysqld-nt --skip-grant-tables
- 然后另外打开一个命入令行窗口,执行mysql,此时无需输入密码即可进入。
- >use mysql
- >update user set password=password("new_pass") where user="root";
- >flush privileges;
- >exit
- 使用任务管理器,找到mysqld-nt的进程,结束进程!
- 在重新启动mysql-nt服务,就可以用新密码登录了。
-
- 在linux下:
- 如果 MySQL 正在运行,首先杀之: killall -TERM mysqld。
- 启动 MySQL :bin/safe_mysqld --skip-grant-tables &
- 就可以不需要密码就进入 MySQL 了。
- 然后就是
- >use mysql
- >update user set password=password("new_pass") where user="root";
- >flush privileges;
- 重新杀 MySQL ,用正常方法启动 MySQL 。
附:使用Mysqladmin更改密码
新手在这个上往往容易范错误,导致不能进入MYSQL,整得非常郁闷。
我来做几个例子相信很快就明白了 。
1、原来的密码是123456
C:\>type mysql5.bat
@echo off
mysql -uroot -p123456 -P3306
正确的修改MYSQL用户密码的格式是:
我们这里用
用户:root(可以换成其他的)
密码:woshiduide
来演示新密码。
C:\>mysqladmin -uroot -p password woshiduide
Enter password: ******
于是修改成功。
注意PASSWORD关键字后面的空格
有好多人是这样修改的:
C:\>mysqladmin -uroot -p password 'woshiduide'
Enter password: ******
C:\>mysqladmin -uroot -p password 'woshiduide'
Enter password: *********
Warning: single quotes were not trimmed from the password by your command
line client, as you might have expected.
而这个时候真正的密码是'woshiduide'
C:\>mysql -uroot -p'woshiduide'
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
而新手往往这样:
C:\>mysql -uroot -pwoshiduide
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Y
ES)
所以非常郁闷,BAIDU、GOOGLE的搜了一大堆。
我现在把密码改回去。
C:\>mysqladmin -uroot -p'woshiduide' password 123456
2、还有就是可以直接进入MYSQL,然后修改密码。
mysql> use mysql
Database changed
mysql> update user set PASSWORD = PASSWORD('woshiduide') where USER='root' and H
OST='localhost';
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
mysql> exit
Bye
C:\>mysql -uroot -pwoshiduide
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
Query OK, 0 rows affected (0.02 sec)
3、还有一种就是用SET PASSWORD 命令修改:
C:\>mysql5.bat
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.17-beta-community-nt-debug-log MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> set password for root@'localhost' = password('woshiduide');
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.09 sec)
mysql> exit
Bye
4、GRANT 也可以,不过这里不介绍。因为涉及到权限的问题。
分享到:
相关推荐
mysql忘记密码解决方法mysql忘记密码解决方法mysql忘记密码解决方法
mysql忘记密码解决办法.docmysql忘记密码解决办法.docmysql忘记密码解决办法.doc
如果忘记mysql的密码,请不要着急,这个文档详细教你如何重新设置新密码
今天我们主要是讲一下关于linux忘记mysql密码处理方法,下面提供了5种linux忘记mysql密码找回方法哦。 方法一(先进入root权限): # /etc/init.d/mysql stop # mysqld_safe --user=mysql --skip-grant-tables --...
windows下忘记mysql的root用户密码详细解决方法
linux mysql忘记密码,自己碰到了,然后解决了,整理的文档
使用此方法可以轻松的解决MYSQL无法访问的问题,虽然文档的内容不是很多,但它是解决问题的利器。
linux--mysql忘记密码,修改密码
解决mysql忘记密码
mysql数据库忘记密码时如何修改 mysql数据库忘记密码时如何修改
MySQL忘记密码的解决方法
解决Mysql数据库忘记密码的问题,已经过验证的解决方法。
mysql忘记超级管理员root密码之后,需要重置密码时请看过来,在文件中可以比较清晰的明白修改的过程,注:这是windows操作系统下的mysql root重置密码的过程
MySQL忘记管理员密码的解决方法,解决你的燃眉之急……
mysql忘记密码的修改步骤mysql忘记密码的修改步骤.
ubuntu 11.10 mysql忘记root密码解决
linux下mysql的root密码忘记解决方法
当您忘记了 Windows 上 MySQL 8.0 的密码时,可以按照以下步骤进行找回: 1. **停止 MySQL 服务**: `net stop MySQL80` 2. **以不检查密码的方式启动 MySQL**: 打开命令提示符(以管理员身份),然后输入以下...
Mysql 重装之后忘记Root密码的解决方法