当前位置:网站首页>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】用coco2017训练Model_zoo上的 yolov4,迭代了两千多batch_size之后报错,大佬们帮忙看看。
- MySQL分库分表
- MySQL大批量造数据
- What is the difference between a cloud database and an on-premises database?
- 技术很牛逼,还需要“向上管理”吗?
- Difference between Object and Map
- Cesium加载离线地图和离线地形
- How to build FTP server under win2003
- 使用MULTISET来比较数据集的实例介绍
猜你喜欢
随机推荐
使用MULTISET来比较数据集的实例介绍
MySQL eight-part text recitation version
Database indexes: indexes are not a panacea
DCM 中间件家族迎来新成员
ImportError:attempted relative import with no known parent package
青蛙跳台阶(递归和非递归)-------小乐乐走台阶
【私人系列】日常PHP遇到的各种稀奇古怪的问题
[flink] Error finishing Could not instantiate the executor. Make sure a planner module is on the classpath
MySQL sub-database sub-table
The advanced version of the cattle brushing series (search for rotating sorted arrays, inversion of the specified range in the linked list)
第一次进入小程序判断
crontab中写go run不执行的问题
The JDBC programming of the MySQL database
The advanced version of the Niu Ke brushing series (team competition, sorting subsequences, inverting strings, deleting common characters, repairing pastures)
MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
MySQL数据库主从配置
MindSpore:mindspore有没有类似tf.GradientTape()用来求解梯度的?
Cesium加载离线地图和离线地形
What is a RESTful API?
Download Win11 how to change the default path?Download Win11 change the default path method








