Mysql修改密码
初次安装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)使用SQL语句再次修改密码
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)]>
登录成功!
6)使用linux命令再次修改密码
1 [root@node1 /]# mysqladmin -u root -p password abcdef (这里abcdef是新密码) 2 Enter password: (输入上一次的密码)
7)使用新密码登录
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 35
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)]>
登录成功!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~