• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
悬溺
博客园    首页    新随笔    联系   管理    订阅  订阅
mysql二进制安装和密码破解

1. 二进制格式mysql安装

进入mysql官方网站找下载地址


部署安装

[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels
[root@localhost src]# ls                   //查看mysql软件包
debug  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
//创建mysql用户和组
[root@localhost src]# useradd -r -M -s /sbin/nologin mysql    
[root@localhost src]# id mysql
uid=992(mysql) gid=987(mysql) 组=987(mysql)
[root@localhost src]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  sbin  share  src
//解压软件包
[root@localhost src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.37-linux-glibc2.12-x86_64  share
[root@localhost local]# mv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root root   6 6月  22 2021 bin
drwxr-xr-x. 2 root root   6 6月  22 2021 etc
drwxr-xr-x. 2 root root   6 6月  22 2021 games
drwxr-xr-x. 2 root root   6 6月  22 2021 include
drwxr-xr-x. 2 root root   6 6月  22 2021 lib
drwxr-xr-x. 3 root root  17 4月  25 10:09 lib64
drwxr-xr-x. 2 root root   6 6月  22 2021 libexec
drwxr-xr-x. 9 root root 129 6月  28 07:57 mysql
drwxr-xr-x. 2 root root   6 6月  22 2021 sbin
drwxr-xr-x. 5 root root  49 4月  25 10:09 share
drwxr-xr-x. 2 root root   6 6月  22 2021 src
[root@localhost local]# chown -R mysql.mysql mysql      //修改目录/usr/local/mysql的属主属组
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root  root    6 6月  22 2021 bin
drwxr-xr-x. 2 root  root    6 6月  22 2021 etc
drwxr-xr-x. 2 root  root    6 6月  22 2021 games
drwxr-xr-x. 2 root  root    6 6月  22 2021 include
drwxr-xr-x. 2 root  root    6 6月  22 2021 lib
drwxr-xr-x. 3 root  root   17 4月  25 10:09 lib64
drwxr-xr-x. 2 root  root    6 6月  22 2021 libexec
drwxr-xr-x. 9 mysql mysql 129 6月  28 07:57 mysql
drwxr-xr-x. 2 root  root    6 6月  22 2021 sbin
drwxr-xr-x. 5 root  root   49 4月  25 10:09 share
drwxr-xr-x. 2 root  root    6 6月  22 2021 src
//添加环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >/etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh 
[root@localhost local]# which mysql
/usr/local/mysql/bin/mysql
    
[root@localhost local]# cd mysql/
[root@localhost mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# cat /etc/ld.so.conf.d/mysql.conf 
/usr/local/mysql/lib
[root@localhost mysql]# ldconfig 
[root@localhost mysql]# vim /etc/man_db.conf 
//建立数据存放目录
[root@localhost ~]# mkdir -p /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data
[root@localhost ~]# ll /opt/
总用量 0
drwx--x--x. 4 root  root  28 5月   4 06:32 containerd
drwxr-xr-x. 2 mysql mysql  6 6月  28 08:32 data

////初始化数据库
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data
2022-06-28T12:34:50.948016Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-28T12:34:51.141622Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-06-28T12:34:51.183751Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-06-28T12:34:51.245587Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: b476206a-f6de-11ec-ad38-000c290cdb6e.
2022-06-28T12:34:51.246510Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-06-28T12:34:52.213910Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-06-28T12:34:52.213952Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-06-28T12:34:52.214421Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-28T12:34:52.253630Z 1 [Note] A temporary password is generated for root@localhost: gHkb4*rl<2(0
//这个命令的最后会生成一个临时密码
[root@localhost ~]# echo 'gHkb4*rl<2(0' > pass
[root@localhost ~]# ls 
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf 
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
#sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost support-files]# cp mysql.server mysqld
[root@localhost support-files]# ll
总用量 36
-rw-r--r--. 1 mysql mysql   773 11月 29 2021 magic
-rwxr-xr-x. 1 root  root  10576 6月  28 08:45 mysqld
-rwxr-xr-x. 1 mysql mysql  1061 11月 29 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 11月 29 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 11月 29 2021 mysql.server
[root@localhost support-files]# chown -R mysql.mysql mysqld
[root@localhost support-files]# ll
总用量 36
-rw-r--r--. 1 mysql mysql   773 11月 29 2021 magic
-rwxr-xr-x. 1 mysql mysql 10576 6月  28 08:45 mysqld
-rwxr-xr-x. 1 mysql mysql  1061 11月 29 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 11月 29 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 11月 29 2021 mysql.server
[root@localhost support-files]# vim mysqld
[root@localhost support-files]# cd
[root@localhost ~]# 
//启动mysql
[root@localhost ~]# /usr/local/mysql/support-files/mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost ~]# 
[root@localhost ~]# ss -antl     //查看状态3306端口
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process     
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                   
LISTEN     0          80                         *:3306                    *:*                   
LISTEN     0          128                     [::]:22                   [::]:*                   
[root@localhost ~]# ps -ef | grep mysqld
root        5518       1  0 08:48 pts/2    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql       5706    5518  1 08:48 pts/2    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root        5741    5279  0 08:49 pts/2    00:00:00 grep --color=auto mysqld
[root@localhost ~]# ls
anaconda-ks.cfg  pass
[root@localhost ~]# cat pass 
gHkb4*rl<2(0
[root@localhost ~]# mysql -uroot -p'gHkb4*rl<2(0'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost ~]# dnf provides libncurses.so.5
MySQL Tools Community                                            101 kB/s | 651 kB     00:06    
MySQL 5.7 Community Server                                       618 kB/s | 2.6 MB     00:04    
上次元数据过期检查:0:00:01 前,执行于 2022年06月28日 星期二 08时51分05秒。
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
仓库        :base
匹配来源:
提供    : libncurses.so.5

[root@localhost ~]# dnf -y install ncurses-compat-libs
上次元数据过期检查:0:00:48 前,执行于 2022年06月28日 星期二 08时51分05秒。
依赖关系解决。
=================================================================================================
 软件包                       架构            版本                           仓库           大小
=================================================================================================
安装:
 ncurses-compat-libs          x86_64          6.1-9.20180224.el8             base          328 k

事务概要
=================================================================================================
安装  1 软件包

总下载:328 k
安装大小:1.0 M
下载软件包:
ncurses-compat-libs-6.1-9.20180224.el8.x86_64.rpm                2.4 MB/s | 328 kB     00:00    
-------------------------------------------------------------------------------------------------
总计                                                             2.3 MB/s | 328 kB     00:00     
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                  1/1 
  安装    : ncurses-compat-libs-6.1-9.20180224.el8.x86_64                                    1/1 
  运行脚本: ncurses-compat-libs-6.1-9.20180224.el8.x86_64                                    1/1 
  验证    : ncurses-compat-libs-6.1-9.20180224.el8.x86_64                                    1/1 

已安装:
  ncurses-compat-libs-6.1-9.20180224.el8.x86_64                                                  

完毕!
//修改密码
//使用临时密码登录           
[root@localhost ~]# mysql -uroot -p'gHkb4*rl<2(0'       
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password = password('runtime123!');       //修改密码
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye
[root@localhost ~]# mysql -uroot -p'runtime123!'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.37 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

//设置开机自启
[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service mysqld.service
[root@localhost ~]# ls
anaconda-ks.cfg  mysqld.service  pass
[root@localhost ~]# vim mysqld.service 
[root@localhost ~]# cat mysqld.service 
[Unit]
Description=mysql server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysqld start
ExecStop=/usr/local/mysql/support-files/mysqld stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target 
[root@localhost ~]# systemctl disable --now firewalld        //关闭防火墙
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# 
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config 
[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# ls
anaconda-ks.cfg  mysqld.service  pass
[root@localhost ~]# vim mysqld.service 
[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# 
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# 
[root@localhost ~]# systemctl status mysqld         
● mysqld.service - mysql server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@localhost ~]# ss -antl
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process     
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                   
LISTEN     0          80                         *:3306                    *:*                   
LISTEN     0          128                     [::]:22                   [::]:*   
[root@localhost ~]# systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

密码破解

mysql密码破解步骤:(只能用root用户来操作)

1.修改配置文件,加入以下内容

​ skip-grant-tables

2.重启mysql

3.修改密码

4.恢复配置文件,删除skip-grant-tables

5.重启mysql

6.验证新密码是否能登录

[root@localhost ~]# rm -f .my.cnf
[root@localhost ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
skip-grant-tables     //添加这个
[root@localhost ~]# systemctl restart mysqld   
[root@localhost ~]# ss -antl
State  Recv-Q  Send-Q   Local Address:Port   Peer Address:Port Process                                                        
LISTEN 0       128            0.0.0.0:22          0.0.0.0:*                                                                   
LISTEN 0       80                   *:3306              *:*                                                                   
LISTEN 0       128               [::]:22             [::]:*                                                                   
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
 
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> update user set authentication_string = password('runtime123') where User = 'root' and Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1      //修改密码
 
mysql> quit
Bye
[root@localhost ~]# vim /etc/my.cnf 
[root@localhost ~]# cat /etc/my.cnf 
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve     //删掉
[root@localhost ~]# systemctl restart mysqld  
[root@localhost ~]# mysql -uroot -p123456     //用新密码登录看是否破解成功
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> quit       //完成
Bye
[root@localhost ~]# 
posted on 2022-06-28 21:53  悬溺·  阅读(144)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3