在linux下:如果 mysql 正在运行,首先杀之: killall -term mysqld。 启动 mysql :bin/safe_mysqld --skip-grant-tables 就可
1.mysqladmin -uroot -poldpassword password newpassword
2.mysql> update mysql.user set password=password('新密码') where user='root';
mysql> flush privileges;
mysql> quit
3.mysql -u root mysql
mysql> update user set password=password(new password) where user='name';
mysql> flush privileges;
mysql> quit
4.可以修改mysql文件夹中的my.ini文件
5.使用set password语句,
mysql> set password for myuser@localhost = password('mypasswd');
6.使用grant ... identified by语句
mysql> grant usage on *.* to myuser@localhost identified by 'mypassword';
在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 。
1)停止windows服务中的mysql实例
2)使用–skip-grant-tables 参数启动mysql,这种模式下,无需root密码就可以登陆mysql.
mysqld-max-nt –skip-grant-tables
3)登陆mysql,,修改密码
c:\documents and settings\binzhang>mysql
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 1 to server version: 5.0.27-community-max-nt
type 'help;' or '\h' for help. type '\c' to clear the buffer.
mysql> use mysql;
database changed
mysql> update user set password=password(root) where user=root;
query ok, 1 row affected (0.07 sec)
rows matched: 1 changed: 1 warnings: 0