MySQL密码问题


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

相关内容