当前位置:网站首页>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
边栏推荐
- win2003下FTP服务器如何搭建
- 【flink】报错整理 Could not instantiate the executor. Make sure a planner module is on the classpath
- coming!Dongfang Selection brings goods to the live broadcast of Longjiang agricultural products
- NXP IMX8QXP replacement DDR model operation process
- Cesium加载离线地图和离线地形
- These services can't ali interview?Then don't go to, the basic notification, etc
- MySQl数据库————DQL数据查询语言
- MySQL复制表结构、表数据的方法
- MySQL性能优化(硬件,系统配置,表结构,SQL语句)
- The advanced version of the cattle brushing series (search for rotating sorted arrays, inversion of the specified range in the linked list)
猜你喜欢
After MySQL grouping, take the largest piece of data [optimal solution]
【无标题】多集嵌套集合使不再有MultipleBagFetchException
Linux下安装MySQL教程
MySQL slow query optimization
Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案
The advanced version of the Niu Ke brushing series (team competition, sorting subsequences, inverting strings, deleting common characters, repairing pastures)
win2003下FTP服务器如何搭建
MindSpore:【JupyterLab】按照新手教程训练时报错
Frog jumping steps (recursive and non-recursive) ------- Xiaolele walks the steps
Alibaba Cloud Martial Arts Headline Event Sharing
随机推荐
Download Win11 how to change the default path?Download Win11 change the default path method
mysql慢查询优化
牛客刷题系列之进阶版(组队竞赛,排序子序列,倒置字符串, 删除公共字符,修理牧场)
crontab中写go run不执行的问题
How to build FTP server under win2003
用jOOQ 3.17投射类型安全的嵌套表记录
Frog jumping steps (recursive and non-recursive) ------- Xiaolele walks the steps
MySQl数据库————DQL数据查询语言
数据库索引:索引并不是万能药
MySQL six-pulse sword, SQL customs clearance summary
Mapped Statements collection does not contain value for的解决方法
MySQL Functions (Classic Collection)
Typora设置标题自动标号
MySQL slow query optimization
ImportError:attempted relative import with no known parent package
MindSpore:数据处理问题
win2003下FTP服务器如何搭建
HCIP --- 企业网的三层架构
MySQL eight-part text recitation version
刷题记录----字符串