修改mysql用户密码的方法

php中文网
发布: 2016-06-07 15:15:38
原创
977人浏览过

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 修改mysql用户密码的方法总结 1.修改root密码 方法1:使用mysqladmin命令 --适用于记得root旧密码,修改root密码 语法: mysqladmin -u用户名 -p旧密码 password 新密码 例如: # mysqladmin -u root

欢迎进入linux社区论坛,与200万技术人员互动交流 >>进入

  修改mysql用户密码的方法总结

  1.修改root密码

  方法1:使用mysqladmin命令

  --适用于记得root旧密码,修改root密码

  语法:

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

  例如:

  # mysqladmin -u root -proot password mysql

  --注意:如当旧密码输入错误时会报如下错误

  # mysqladmin -u root -proot1 password mysql

  mysqladmin: connect to server at 'localhost' failed

  error: 'Access denied for user 'root'@'localhost' (using password: YES)'

  方法2:直接更新user表password字段

  --适用于忘记root密码,而对root密码进行重置

  

  Step 1: 修改MySQL的登录设置

  # vi /etc/my.cnf

  --windows系统是my.ini文件

  --在[mysqld]的段中加上一句:skip-grant-tables,如没有[mysqld]字段,可手动添加上

  [mysqld]

  datadir=/var/lib/mysql

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

  skip-name-resolve

  skip-grant-tables

  Step 2: 重新启动mysql

  [root@gc ~]# service mysql restart

  Shutting down MySQL..[确定]

  Starting MySQL...[确定]

  Step 3: 登录并修改MySQL的root密码

  --此时直接用mysql即可无需密码即可进入数据库了

  [root@gc ~]# mysql

  Welcome to the MySQL monitor.  Commands end with ; or \g.

  Your MySQL connection id is 2

  Server version: 5.5.24 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> use mysql;

  Database changed

  mysql> update user set password=password('new_password') where user='root';

  Query OK, 5 rows affected (0.00 sec)

  Rows matched: 5  Changed: 5  Warnings: 0

  mysql> flush privileges;

  Query OK, 0 rows affected (0.00 sec)

  --注意:如果没做step1,直接用mysql登录时会报如下错误

  [root@gc ~]# mysql

  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

  Step 4: 将MySQL的登录设置修改回来

  再删除/etc/my.cnf文件中的skip-grant-tables

  Step 5: 重新启动mysql

  [root@gc ~]# service mysql restart

  Shutting down MySQL..[确定]

  Starting MySQL...[确定]

修改mysql用户密码的方法

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号