mysql关于用户密码的设置( 修改、重置、找回)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql关于用户密码的设置( 修改、重置、找回),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5706字,纯文字阅读大概需要9分钟。
内容图文
![mysql关于用户密码的设置( 修改、重置、找回)](/upload/InfoBanner/zyjiaocheng/1137/7a3da2c577fd4efcad93f432a75ba612.jpg)
1. 登录mysql
1.1 单实例登录
1) mysql 刚装完mysql无密码情况下登录
2) mysql–u root 刚装完mysql无密码情况下登录
3) mysql–u root –p 标准的dba登录
3) mysql–u root –p ‘ 密码’ 无交互登录。一般不用,容易泄漏密码
登录成功后 提示:mysql>
1.2 多实例登录
mysql –u root –S 指定mysql.sock文件的位置
提示:和单实例唯一的区别是多实例需要指定mysql.sock的位置
2. 修改用户密码
1.1 交互式修改root密码
-
-
单实例:mysqladmin–u root –p password ‘新密码’
-
[root@Mysql ~]# mysqladmin -u root -p password ‘jeck123‘ Enter password: ----->输入旧密码
-
-
多实例:mysqladmin –u root –p password ‘新密码’ -S mysql.sock的位置
-
[root@Mysql ~]# mysqladmin -u root -p password ‘jeck123‘ -S/usr/local/mysql/tmp/mysql.sock Enter password: ----->输入旧密码
注意:若刚装完 mysql ,则 root 密码为空,直接回车即可
1.2 非交互式修改root密码
-
-
单实例:mysqladmin –u root –p‘旧密码’ password ‘新密码’(注意-p后面无空格)
-
[root@Mysql ~]# mysqladmin -uroot -p‘jeck123‘ password ‘123jeck‘
-
-
多实例:mysqladmin –u root –p‘旧密码’ password ‘新密码’ -S mysql.sock的位置
-
[root@Mysql ~]# mysqladmin -uroot -p‘jeck123‘ password ‘123jeck‘-S /usr/local/mysql/tmp/mysql.sock
这种用于非交互式修改密码,适用于脚本
1.3 在mysql数据库中修改密码
方法一:(只能修改当前登录mysql用户的密码)
[root@Mysql ~]# mysql -uroot -p123jeck Welcometo the MySQL monitor. Commands end with; or \g. YourMySQL connection id is 4 Serverversion: 5.1.56-log Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software, andyou are welcome to modify and redistribute it under the GPL v2 license Type‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> setpassword=password(‘456jeck‘); Query OK, 0 rows affected (0.00 sec) mysql> flushprivileges; Query OK, 0 rows affected (0.00 sec) mysql> exit
方法二:(可以修改任意用户的密码,只要有修改权限)
[root@Mysql ~]# mysql -uroot -p456jeck Welcometo the MySQL monitor. Commands end with; or \g. YourMySQL connection id is 6 Serverversion: 5.1.56-log Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software, andyou are welcome to modify and redistribute it under the GPL v2 license Type‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> updatemysql.user set password=PASSWORD(‘789jeck‘) where user=‘root‘; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed:3 Warnings: 0 mysql> flushprivileges; Query OK, 0 rows affected (0.00 sec) mysql>
3. 找回用户密码
3.1 关闭mysql
[root@Mysql~]# service mysqld stop Shuttingdown MySQL. SUCCESS! [root@Mysql ~]# netstat -lnt | grep mysqld
3.2 用mysqld_safe启动mysql,需要加—skip-grant-tables(忽略授权验证)
单实例:
[root@Mysql~]# /usr/local/mysql/bin/mysqld_safe--skip-grant-tables & --->加&,使进程在后台运行 [1]28643 15010315:56:25 mysqld_safe Logging to ‘/usr/local/mysql-5.1.56/data/Mysql.err‘. 15010315:56:25 mysqld_safe Starting mysqld daemon with databases from/usr/local/mysql-5.1.56/data [root@Mysql ~]# mysql -uroot -p Enter password: ---->直接回车,因为已经忽略验证 Welcometo the MySQL monitor. Commands end with; or \g. YourMySQL connection id is 1 Serverversion: 5.1.56-log Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software, andyou are welcome to modify and redistribute it under the GPL v2 license Type‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> setpassword=password(‘jeck123‘); --->此方法不行 ERROR 1290 (HY000): The MySQL server is running with the--skip-grant-tables option so it cannot execute this statement mysql> updatemysql.user set password=PASSWORD(‘jeck123‘) where user=‘root‘; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed:3 Warnings: 0 mysql> flushprivileges; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
多实例:
[root@Mysql~]# /usr/local/mysql/bin/mysqld_safe--defaults-file=/etc/my.cnf --skip-grant-tables & [1]28643 15010315:56:25 mysqld_safe Logging to ‘/usr/local/mysql-5.1.56/data/Mysql.err‘. 15010315:56:25 mysqld_safe Starting mysqld daemon with databases from/usr/local/mysql-5.1.56/data [root@Mysql ~]# mysql -uroot -p -S/usr/local/mysql/tmp/mysql.sock Enter password: ---->直接回车,因为已经忽略验证 Welcometo the MySQL monitor. Commands end with; or \g. YourMySQL connection id is 1 Serverversion: 5.1.56-log Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software, andyou are welcome to modify and redistribute it under the GPL v2 license Type‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> updatemysql.user set password=PASSWORD(‘jeck123‘) where user=‘root‘; ---->修改root密码 Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed:3 Warnings: 0 mysql> flushprivileges; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
3.3 重新启动mysql(必须重新启动)
[root@Mysql~]# service mysqld restart Shuttingdown MySQL.150103 16:07:17 mysqld_safe mysqld from pid file/usr/local/mysql-5.1.56/data/Mysql.pid ended SUCCESS! StartingMySQL. SUCCESS! [1]+ Done /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
3.4 用新修改的密码就可以登录了
[root@Mysql~]# mysql -uroot -pjeck123 Welcometo the MySQL monitor. Commands end with; or \g. YourMySQL connection id is 1 Serverversion: 5.1.56-log Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software, andyou are welcome to modify and redistribute it under the GPL v2 license Type‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql>
本文出自 “Study-Everyday” 博客,请务必保留此出处http://studys.blog.51cto.com/9736817/1599104
原文:http://studys.blog.51cto.com/9736817/1599104
内容总结
以上是互联网集市为您收集整理的mysql关于用户密码的设置( 修改、重置、找回)全部内容,希望文章能够帮你解决mysql关于用户密码的设置( 修改、重置、找回)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。