mysql命令模式修改mysql root密码笔记

今天在服务器中安装好了一个mysql服务器了,起初是配置好的mysql的root密码了,但经过一些软件的优化之后把root密码改成了空了,因为刚安装好的环境没有像mysql管理工具了,所以只有在命令模式下使用mysqladmin进行修改了,下面111cn站长为各位介绍一下mysql命令模式修改mysql root密码方法。

修改mysql密码过程如下:

百度搜索一文章看到使用.

格式:mysqladmin -u用户名 -p旧密码 password 新密码

修改于时我下看操作:

  1. Enter password:
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 10
  4. Server version: 5.5.27-log MySQL Community Server (GPL)
  5. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. mysql> mysqladmin -u root password 我要设置的密码
  11. ->
  12. -> ;
  13. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
  14. corresponds to your MySQL server version for the right syntax to use near 'mysql
  15. admin -u root password 我要设置的密码' at line 1
  16. mysql> mysqladmin -u root -password 我要设置的密码
  17. -> ;
  18. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
  19. corresponds to your MySQL server version for the right syntax to use near 'mysql --phpfensi.com
  20. admin -u root -password 我要设置的密码' at line 1

最后小编使用了 mysqladmin -u root -password 我要设置的密码 无法搞定,突然想到直接更新表即可.

  1. mysql> update mysql.user set password=PASSWORD('我要设置的密码') where User ='root
  2. ';
  3. Query OK, 3 rows affected (0.05 sec)
  4. Rows matched: 3 Changed: 3 Warnings: 0
  5. mysql> flush privileges;
  6. Query OK, 0 rows affected (0.01 sec)
  7. mysql>

好了这样就搞定了,虽然过程不复杂也不简单.