MySql密码
1、启动关闭MySQL
[root@mysql ~]# systemctl start mysqld.service
[root@mysql ~]# systemctl stop mysqld.service
2、登录与退出
格式:mysql [选项]
mysql [-u]
MySQL密码的修改与破解 1、启动关闭MySQL [root@mysql ~]# systemctl start mysqld.service [root@mysql ~]# 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 root@localhost identified by 'ABCabc123!'; //必须遵循密码复杂性要求 Query OK, 0 rows affected (0.01 sec) //密码复杂性要求:要有大小写字母数字和特殊符号 mysql> show databases; //密码生效后可以立即进行操作 3、修改root密码 1)在命令行上会显示出新设置的密码 [root@mysql ~]# mysqladmin -uroot -p password 'ABCabc123!' Enter password: //输入旧密码(如果是yum仓库仓库安装,旧密码为空,直接回车即可) //密码修改成功,提示:在命令行界面上使用密码可能不安全,由于密码将以明文形式发送到服务器 [root@mysql ~]# mysql -uroot -p Enter password: //输入修改后的密码,ABCabc123! 2)不会显示出新设置的密码 [root@mysql ~]# mysqladmin -uroot -p password //密码设置成功 先登录数据库 [root@mysql ~]# mysql -uroot -p Enter password: mysql> alter user root@localhost identified by 'ABCabc123!'; Query OK, 0 rows affected (0.01 sec) //新密码设置成功 mysql> exit Bye [root@mysql ~]# mysql -uroot -p Enter password: //使用新密码重新登录数据库 先登录数据库 [root@mysql ~]# mysql -uroot -p Enter password: mysql> set password for 'root'@'localhost' = '!ABCabc123'; Query OK, 0 rows affected (0.01 sec) //新密码设置成功 mysql> exit Bye [root@mysql ~]# mysql -uroot -p Enter password: //使用新密码重新登录数据库 先登录数据库 [root@mysql ~]# 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) 登录测试: [root@mysql ~]# mysql -uroot -p Enter password: //空密码,直接回车即可登录 4、重置root密码 重置root密码的官方文档说明: [root@mysql ~]# vim /tmp/mysql-init alter user 'root'@'localhost' identified by '#BAIgou666'; [root@mysql ~]# tail -f /var/log/mysql/mysqld.log //查看日志 新开一个终端,在新开的终端上进行下一步操作: [root@mysql ~]# systemctl stop mysqld [root@mysql ~]# mysqld --init-file=/tmp/mysql-init --user=mysql & [1] 14697 在有日志的终端上查看日志信息: //由图可知启动成功 启动成功后退出即可,在新开的终端上停止数据库: [root@mysql ~]# killall mysqld //杀掉所有mysqld进程 [root@mysql ~]# ps -ef | grep mysql //过滤查看还有没有mysql的进程,结果没有 [root@mysql ~]# ps -ef | grep 14697 //过滤进程14697是否已经关闭mssql数据库密码,结果已经关闭 root 15009 14600 0 04:36 pts/1 00:00:00 grep --color=auto 14697 重启服务,使用新密码登录: [root@mysql ~]# systemctl restart mysqld [root@mysql ~]# mysql -uroot -p Enter password: //使用新密码登录 [root@mysql ~]# systemctl stop mysqld //停止服务 [root@mysql ~]# mysqld --user=mysql --skip-grant-tables //启动时跳过权限表:--skip-grant-tables 终端无法继续使用,新开一个终端进行之后的步骤: 修改面命: [root@mysql ~]# mysql mysql> flush privileges; //刷新权限表,否则会报错 Query OK, 0 rows affected (0.01 sec) mysql> alter user root@localhost 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 [root@mysql ~]# killall mysqld [root@mysql ~]# systemctl restart mysqld [root@mysql ~]# mysql -uroot -p (编辑:晋中站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |