首页 > 数据库技术 > 详细

Mysql修改密码

时间:2019-06-06 15:10:31      阅读:108      评论:0      收藏:0      [点我收藏+]

初次安装MySQL默认没有密码,安装完毕之后最好增加密码

1、命令

1 #/usr/bin/mysqladmin -u root password new-password

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

2、例子
例1:给root加个密码admin
键入以下命令 :

1 [root@node1]# /usr/bin/mysqladmin -u root password admin

注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。

3、测试是否修改成功
  1)不用密码登录

1 [root@node1 /]# mysql
2 ERROR 1045: Access denied for user: root@localhost (Using password: NO)

显示错误,说明密码已经修改。
2)用修改后的密码登录

1 [root@node1 /]# mysql -u root -p
2 Enter password: (输入修改后的密码admin)
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]>

成功!
这是通过mysqladmin命令修改口令,也可通过修改库来更改口令。

4)再次修改密码

1 [root@node1 /]# mysql -u root -p
2 Enter password: (输入修改后的密码admin)
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> set password=password(‘123456‘);
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> exit
Bye

5)用再次修改后的密码登录

1 [root@node1 /]# mysql -u root -p
2 Enter password: (输入再次修改后的密码)
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 29
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]>

登录成功!

Mysql修改密码

原文:https://www.cnblogs.com/kiko-sunrise/p/10984826.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!