当前位置:网站首页>MySql密码
MySql密码
2022-07-30 19:41:00 【每天一个001】
MySQL密码的修改与破解
1、启动关闭MySQL
[[email protected] ~]# systemctl start mysqld.service
[[email protected] ~]# systemctl stop mysqld.service
2、登录与退出
格式:mysql [选项]
mysql [-u]用户;[-p]密码;[-h]IP地址;[-D]数据库名;[-P]端口
注:选项[-p]密码,不能有空格,密码有特殊字符,需要用单引号括起来。(8.0版禁止将密码写在选项-p后面)
如果使用的是离线安装,会生成一个临时密码,使用临时密码登录数据库后会显示无法正常使用,会提示需要修改密码;
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. //报错原因:需要先修改密码,才能正常使用MySQL
修改root密码:
mysql> alter user [email protected] identified by 'ABCabc123!'; //必须遵循密码复杂性要求
Query OK, 0 rows affected (0.01 sec) //密码复杂性要求:要有大小写字母数字和特殊符号
mysql> show databases; //密码生效后可以立即进行操作
3、修改root密码
方法一:mysqladmin
1)在命令行上会显示出新设置的密码
[[email protected] ~]# mysqladmin -uroot -p password 'ABCabc123!'
Enter password: //输入旧密码(如果是yum仓库仓库安装,旧密码为空,直接回车即可)
//密码修改成功,提示:在命令行界面上使用密码可能不安全,由于密码将以明文形式发送到服务器
[[email protected] ~]# mysql -uroot -p
Enter password: //输入修改后的密码,ABCabc123!
2)不会显示出新设置的密码
[[email protected] ~]# mysqladmin -uroot -p password
//密码设置成功
方法二:alter user
先登录数据库
[[email protected] ~]# mysql -uroot -p
Enter password:
mysql> alter user [email protected] identified by 'ABCabc123!';
Query OK, 0 rows affected (0.01 sec) //新密码设置成功
mysql> exit
Bye
[[email protected] ~]# mysql -uroot -p
Enter password: //使用新密码重新登录数据库
方法三:set password for
先登录数据库
[[email protected] ~]# mysql -uroot -p
Enter password:
mysql> set password for 'root'@'localhost' = '!ABCabc123';
Query OK, 0 rows affected (0.01 sec) //新密码设置成功
mysql> exit
Bye
[[email protected] ~]# mysql -uroot -p
Enter password: //使用新密码重新登录数据库
方法四:update表
先登录数据库
[[email protected] ~]# mysql -uroot -p
Enter password:
mysql> use mysql;
mysql> update user set authentication_string='' where user='root'; //以明文形式重送密码,密码只能设置为空
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges; //刷新权限表,否则会导致此次密码修改失败
Query OK, 0 rows affected (0.00 sec)
登录测试:
[[email protected] ~]# mysql -uroot -p
Enter password: //空密码,直接回车即可登录
4、重置root密码
重置root密码的官方文档说明:https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
方法一:
[[email protected] ~]# vim /tmp/mysql-init
alter user 'root'@'localhost' identified by '#BAIgou666';
[[email protected] ~]# tail -f /var/log/mysql/mysqld.log //查看日志
新开一个终端,在新开的终端上进行下一步操作:
[[email protected] ~]# systemctl stop mysqld
[[email protected] ~]# mysqld --init-file=/tmp/mysql-init --user=mysql &
[1] 14697
在有日志的终端上查看日志信息:
//由图可知启动成功
启动成功后退出即可,在新开的终端上停止数据库:
[[email protected] ~]# killall mysqld //杀掉所有mysqld进程
[[email protected] ~]# ps -ef | grep mysql //过滤查看还有没有mysql的进程,结果没有
[[email protected] ~]# ps -ef | grep 14697 //过滤进程14697是否已经关闭,结果已经关闭
root 15009 14600 0 04:36 pts/1 00:00:00 grep --color=auto 14697
重启服务,使用新密码登录:
[[email protected] ~]# systemctl restart mysqld
[[email protected] ~]# mysql -uroot -p
Enter password: //使用新密码登录
方法二:
[[email protected] ~]# systemctl stop mysqld //停止服务
[[email protected] ~]# mysqld --user=mysql --skip-grant-tables //启动时跳过权限表:--skip-grant-tables
终端无法继续使用,新开一个终端进行之后的步骤:
修改面命:
[[email protected] ~]# mysql
mysql> flush privileges; //刷新权限表,否则会报错
Query OK, 0 rows affected (0.01 sec)
mysql> alter user [email protected] IDENTIFIED BY '#baiGOU666';
//设置密码,也可以使用update user set authentication_string='' where user='root'(使用这条命令设置密码为空,要先切换到mysql数据库,即use mysql; )
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[[email protected] ~]# killall mysqld
[[email protected] ~]# systemctl restart mysqld
[[email protected] ~]# mysql -uroot -p
边栏推荐
- MySQL database - views and indexes
- Linux下安装Mysql5.7,超详细完整教程,以及云mysql连接
- mysql8 installation under linux
- MySQL数据库————视图和索引
- DCM 中间件家族迎来新成员
- mysql慢查询优化
- The 17th "Revitalization Cup" National Youth Vocational Skills Competition - Computer Programmers (Cloud Computing Platform and Operation and Maintenance) Participation Review and Summary
- 为单行查询设置JDBC Statement.setFetchSize()为1的方法指南
- MindSpore:【resnet_thor模型】尝试运行resnet_thor时报Could not convert to
- [flink] Error finishing Could not instantiate the executor. Make sure a planner module is on the classpath
猜你喜欢
Linux下安装MySQL教程
How to build FTP server under win2003
Maxwell 一款简单易上手的实时抓取Mysql数据的软件
PostgreSQL 14.4如何安装使用
Zabbix 5.0 监控教程(一)
青蛙跳台阶(递归和非递归)-------小乐乐走台阶
MindSpore: CV.Rescale(rescale,shift)中参数rescale和shift的含义?
Alibaba Cloud Martial Arts Headline Event Sharing
MySQL database - views and indexes
用jOOQ 3.17投射类型安全的嵌套表记录
随机推荐
MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
又一家公司面试的内容
浅聊对比学习(Contrastive Learning)第一弹
[hbuilder] cannot run some projects, open the terminal and cannot enter commands
MySQL复制表结构、表数据的方法
musicApp 的.eslintrc.js
HCIP --- 企业网的三层架构
Win11如何更改默认下载路径?Win11更改默认下载路径的方法
How to copy table structure and table data in MySQL
Alibaba Cloud Martial Arts Headline Event Sharing
MySQL分组后取最大一条数据【最优解】
Cesium加载离线地图和离线地形
MySQL性能优化(硬件,系统配置,表结构,SQL语句)
第十七届“振兴杯”全国青年 职业技能大赛——计算机程序设计员(云计算平台与运维)参赛回顾与总结
MindSpore:【MindSpore1.1】Mindspore安装后验证出现cudaSetDevice failed错误
MySQL six-pulse sword, SQL customs clearance summary
青蛙跳台阶(递归和非递归)-------小乐乐走台阶
Database indexes: indexes are not a panacea
Day31 LeetCode
VS Code 连接SQL Server