mysql二进制安装与密码破解
1:二进制安装
进入包存放的路径
[root@localhost src]# cd /usr/src/
创建mysql的用户
[root@localhost src]# useradd -M -r -s /sbin/nologin mysql
[root@localhost src]# id mysql
uid=975(mysql) gid=974(mysql) 组=974(mysql)
将安装包解压至/usr/local
[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 etc games include lib lib64 libexec mysql-5.7.37-linux-glibc2.12-x86_64 sbin share src
[root@localhost local]# ln -sv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.37-linux-glibc2.12-x86_64/'
[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 3月 6 20:08 lib64
drwxr-xr-x. 2 root root 6 6月 22 2021 libexec
lrwxrwxrwx. 1 root root 36 7月 26 18:40 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 7月 26 18:37 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 6月 22 2021 sbin
drwxr-xr-x. 5 root root 49 3月 6 20:08 share
drwxr-xr-x. 2 root root 6 6月 22 2021 src
[root@localhost local]#
修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll mysql -d
lrwxrwxrwx. 1 mysql mysql 36 7月 26 18:40 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
编写环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh
[root@localhost local]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
将mysql的头文件输出给系统
[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
root@localhost mysql]# ll /usr/include/
总用量 0
drwxr-xr-x. 4 root root 34 3月 6 20:13 gnome-boxes
lrwxrwxrwx. 1 root root 24 7月 26 18:46 mysql -> /usr/local/mysql/include
配置man帮助手册
[root@localhost mysql]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/local/mysql/man
增添额外库文件
[root@localhost mysql]# echo '/var/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# ldconfig
建立数据存放目录
[root@localhost mysql]# mkdir /opt/data
[root@localhost mysql]# chown -R mysql.mysql /opt/data/
[root@localhost mysql]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 7月 26 18:58 data
初始化数据库
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2022-07-26T10:59:26.939711Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-26T10:59:27.097891Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-26T10:59:27.122982Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-26T10:59:27.127555Z 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: 043007c0-0cd2-11ed-b67d-000c295a7a3f.
2022-07-26T10:59:27.128074Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-26T10:59:27.670720Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-26T10:59:27.670745Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-26T10:59:27.671135Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-26T10:59:27.803704Z 1 [Note] A temporary password is generated for root@localhost: 9p4#<?1ipRus
生成配置文件
[root@localhost mysql]# vim /etc/my.cnf
[root@localhost mysql]# 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 mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data
启动mysql
[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL SUCCESS!
[root@localhost ~]# ps -ef | grep mysql
root 2787 1 0 19:06 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql 2987 2787 0 19:06 ? 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 7158 2251 0 19:08 pts/0 00:00:00 grep --color=auto mysql
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
[root@localhost ~]#
2:破解密码
向mysql配置文件my.cnf中添加免除授权
[root@localhost ~]# vim /etc/my.cnf
skip-grant-tables
添加后报错缺少东西那就去下
root@localhost mysql]# mysql
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost mysql]# dnf -y install libncurses.so.5*
上次元数据过期检查:1:01:05 前,执行于 2022年07月26日 星期二 18时49分17秒。
依赖关系解决。
已安装:
ncurses-compat-libs-6.1-9.20180224.el8.x86_64
完毕!
再次登录
[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>
修改mysql数据库root密码,并刷新权限
mysql> update user set authentication_string:=password ('XUANning@123') where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
删掉配置文件里的跳过授权使用我们新修改的密码登录mysql,破解密码成功
[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 ~]# mysql -uroot -pXUANning@123
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
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>