MYSQ-更改密码总结

1、对原始密码的更改:

mysql> update user set password=password('w123123') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3   Changed: 3   Warnings: 0

mysql> quit
Bye

测试:

C:\Documents and Settings\Administrator>mysql --protocol=pipe -uroot -p
Enter password: *******
Welcome to the MySQL monitor.   Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.25-log MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| #mysql50#bin-log   |
| mysql               |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.03 sec)

mysql> quit
Bye

2、若忘记密码了,要更改登陆,方法如下:

需要两CMD窗口:
第一个:

C:\Documents and Settings\Administrator>mysqld --skip-grant-tables
开启后就可以了

第二个:

空密码进入
C:\Documents and Settings\Administrator>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.   Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.25-log MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| #mysql50#bin-log   |
| mysql               |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.09 sec)

mysql> use mysql
Database changed
mysql> update user set password=password('w111') where user='root'
    -> ;
Query OK, 3 rows affected (0.06 sec)
Rows matched: 3   Changed: 3   Warnings: 0

mysql> quit
Bye
也可以加入( mysql> flush privileges;  执行改操作

关闭:第一个窗口,最主要的是停止了mysqld进程(在任务管理器中查看是否存在)

重启mysql服务:

带密码登陆

C:\Documents and Settings\Administrator>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor.   Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.25-log MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| #mysql50#bin-log   |
| mysql               |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.05 sec)

mysql>

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| #mysql50#bin-log   |
| mysql               |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.05 sec)

mysql>

这样更改密码成功!!!

3、mysqladmin修改密码:

C:\Documents and Settings\Administrator>mysqladmin -u root -p password w123123
Enter password: ****

测试:

C:\Documents and Settings\Administrator>mysql -uroot -p
Enter password: *******
Welcome to the MySQL monitor.   Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.25-log MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

注意:这个是mysql本身就有密码!!!这是需要 -p 参数!!

如果本身mysql没有密码:
则:

C:\Documents and Settings\Administrator>mysqladmin -u root   password w123123

注意两者的区别!!!

你可能感兴趣的:(it)