当前位置:网站首页>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
边栏推荐
- 【flink】报错整理 Could not instantiate the executor. Make sure a planner module is on the classpath
- MindSpore:【Resolve node failed】解析节点失败的问题
- MindSpore:【语音识别】DFCNN网络训练loss不收敛
- MindSpore:数据处理问题
- Linux下安装Mysql5.7,超详细完整教程,以及云mysql连接
- Linux下最新版MySQL 8.0的下载与安装(详细步骤)
- 云数据库和本地数据库有什么区别?
- MySQL mass production of data
- linux下mysql8安装
- MySQL database - views and indexes
猜你喜欢
【PyTorchVideo教程01】快速实现视频动作识别
Perfectly Clear QuickDesk & QuickServer图像校正优化工具
[Node implements data encryption]
技术很牛逼,还需要“向上管理”吗?
What is the difference between a cloud database and an on-premises database?
MySQL slow query optimization
Database indexes: indexes are not a panacea
MindSpore:【MindSpore1.1】Mindspore安装后验证出现cudaSetDevice failed错误
MySQL mass production of data
Alibaba Cloud Martial Arts Headline Event Sharing
随机推荐
Object和Map的区别
Encapsulates a console file selector based on inquirer
浅聊对比学习(Contrastive Learning)第一弹
PostgreSQL 14.4如何安装使用
青蛙跳台阶(递归和非递归)-------小乐乐走台阶
Snowflake vs. Redshift的2022战报:两个数据平台谁更适合你?
Difference between Object and Map
MySQL mass production of data
Download Win11 how to change the default path?Download Win11 change the default path method
MindSpore:【模型训练】【mindinsight】timeline的时间和实际用时相差很远
[flink] Error finishing Could not instantiate the executor. Make sure a planner module is on the classpath
看完《二舅》,我更内耗了
Install Mysql5.7 under Linux, super detailed and complete tutorial, and cloud mysql connection
阿里面试官:给我描述一下缓存击穿的现象,并说说你的解决思路?
Linux下载安装mysql5.7版本教程最全详解
MySQL sub-database sub-table
The advanced version of the Niu Ke brushing series (team competition, sorting subsequences, inverting strings, deleting common characters, repairing pastures)
牛客刷题系列之进阶版(组队竞赛,排序子序列,倒置字符串, 删除公共字符,修理牧场)
Golang logging library zerolog use record
Range.CopyFromRecordset method (Excel)