mysql的密码忘记了怎么办

linux下

1、修改MySQL的登录设置:

# vi /etc/my.cnf

[mysqld]的段中加上一句:skip-grant-tables

例如:

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

skip-name-resolve

skip-grant-tables

保存并且退出vi

3.重新启动mysqld

# /etc/init.d/mysqld restart

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

4.登录并修改MySQLroot密码

# /usr/bin/mysql

Welcome to the MySQL monitor. Commands endwith ; or \g.

Your MySQL connection id is 3 to serverversion: 3.23.56

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ toclear the buffer.

mysql> USE mysql ;

Reading table information for completion oftable and column names

You can turn off this feature to get aquicker startup with -A

Database changed

mysql> UPDATE user SET Password =password ( ‘new-password’ ) WHERE User = ‘root’ ;

Query OK, 0 rows affected (0.00 sec)

Rows matched: 2 Changed: 0 Warnings: 0

mysql> flush privileges ;

Query OK, 0 rows affected (0.01 sec)

mysql> quit

Bye

5.将MySQL的登录设置修改回来

# vi /etc/my.cnf

将刚才在[mysqld]的段中加上的skip-grant-tables删除

保存并且退出vi

6.重新启动mysqld

# /etc/init.d/mysqld restart

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

windows下

1.以系统管理员身份登陆系统。

  2.打开cmd―�Cnet start 查看mysql是否启动。启动的话就停止netstop mysql.

  3.我的mysql安装在d:\usr\local\mysql4\bin下。

  4.跳过权限检查启动mysql.

 d:\usr\local\mysql4\bin\mysqld-nt �Cskip-grant-tables

  5.重新打开cmd。进到d:\usr\local\mysql4\bin下:

 d:\usr\local\mysql4\bin\mysqladmin -uroot flush-privileges password“newpassword”

 d:\usr\local\mysql4\bin\mysqladmin -u root -p shutdown 这句提示你重新输密码。

  6.cmdnet start mysql

  7.搞定了。


你可能感兴趣的:(linux,mysql,密码,welcome)