二进制格式mysql安装和数据库密码破解

二进制格式mysql安装

下载二进制格式的mysql软件包

[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]#

创建用户

[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]# ls
debug  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.37-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost src]#

创建软连接

[root@localhost src]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ll | grep mysql
lrwxrwxrwx. 1 root root  36 7月  26 05:51 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 7月  26 05:50 mysql-5.7.37-linux-glibc2.12-x86_64
[root@localhost local]#

修改目录/usr/local/mysql的属主属组和主包目录的属主属组

[root@localhost local]# cd
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64/
[root@localhost local]# ll | grep mysql
lrwxrwxrwx. 1 mysql mysql  36 7月  26 05:51 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 7月  26 05:50 mysql-5.7.37-linux-glibc2.12-x86_64
[root@localhost local]#

添加环境变量

[root@localhost local]# cd mysql
[root@localhost mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@localhost mysql]# cat /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

修改头文件

[root@localhost mysql]# ln -s /usr/local/mysql/include/ /usr/local/include/myspl
[root@localhost ~]# cd /usr/local/include/
[root@localhost include]# ll
总用量 0
lrwxrwxrwx. 1 root root 25 7月  26 06:15 myspl -> /usr/local/mysql/include/
[root@localhost include]#

修改man文件路径

[root@localhost ~]# vim /etc/man_db.conf
....
#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/mysql/man
#---------------------------------------------------------
# set up PATH to MANPATH mapping
# ie. what man tree holds man pages for what binary directory.
....

增添额外库文件搜索路径

[root@localhost ~]# cd /etc/ld.so.conf.d/
[root@localhost ld.so.conf.d]# ls
kernel-4.18.0-358.el8.x86_64.conf  libiscsi-x86_64.conf
[root@localhost ld.so.conf.d]# vim  mysql.conf
[root@localhost ld.so.conf.d]# cat mysql.conf
/usr/local/mysql/bin
[root@localhost ld.so.conf.d]# ldconfig

建立数据存放目录

[root@localhost ~]# cd /usr/local/mysql
[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 06:31 data
[root@localhost mysql]#

初始化数据库

[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2022-07-26T10:33:32.207664Z 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:33:32.377040Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-26T10:33:32.408748Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-26T10:33:32.414193Z 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: 65819912-0cce-11ed-9c51-000c29a3510a.
2022-07-26T10:33:32.414939Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-26T10:33:32.962684Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-26T10:33:32.962712Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-26T10:33:32.963099Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-26T10:33:33.013899Z 1 [Note] A temporary password is generated for root@localhost: .iAjtda?J7VD
[root@localhost ~]#
//请注意,这个命令的最后会生成一个临时密码,此处密码是.iAjtda?J7VD
//再次注意,这个密码是随机的,你的不会跟我一样,一定要记住这个密码,因为一会登录时会用到

生成配置文件

[root@localhost ~]# vim /etc/my.conf
sedir = /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 ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# vim /etc/init.d/mysqld
....
# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mysql
datadir=/opt/data
....

启动mysql

[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS!
[root@localhost ~]# ss -antlp
State          Recv-Q         Send-Q                   Local Address:Port                   Peer Address:Port         Process
LISTEN         0              32                       192.168.122.1:53                          0.0.0.0:*             users:(("dnsmasq",pid=1947,fd=6))
LISTEN         0              128                            0.0.0.0:22                          0.0.0.0:*             users:(("sshd",pid=1216,fd=5))
LISTEN         0              5                            127.0.0.1:631                         0.0.0.0:*             users:(("cupsd",pid=1224,fd=10))
LISTEN         0              128                          127.0.0.1:6010                        0.0.0.0:*             users:(("sshd",pid=3252,fd=15))
LISTEN         0              128                            0.0.0.0:111                         0.0.0.0:*             users:(("rpcbind",pid=1004,fd=4),("systemd",pid=1,fd=28))
LISTEN         0              128                               [::]:22                             [::]:*             users:(("sshd",pid=1216,fd=7))
LISTEN         0              5                                [::1]:631                            [::]:*             users:(("cupsd",pid=1224,fd=9))
LISTEN         0              128                              [::1]:6010                           [::]:*             users:(("sshd",pid=3252,fd=14))
LISTEN         0              80                                   *:3306                              *:*             users:(("mysqld",pid=5650,fd=23))
LISTEN         0              128                               [::]:111                            [::]:*             users:(("rpcbind",pid=1004,fd=6),("systemd",pid=1,fd=31))
[root@localhost ~]#

修改密码,使用临时密码登录(此处报错需要下载libncurses.so.5来解决)

[root@localhost ~]# mysql -uroot -p'.iAjtda?J7VD'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost ~]# dnf -y install libncurses.so.5*
...
已安装:
  glibc-2.28-184.el8.i686      glibc-gconv-extra-2.28-184.el8.i686      libgcc-8.5.0-10.el8.i686      libstdc++-8.5.0-10.el8.i686      ncurses-compat-libs-6.1-9.20180224.el8.i686
...
[root@localhost ~]# mysql -uroot -p'.iAjtda?J7VD'  //临时密码
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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye
[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 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.

mysql>

数据库破解密码

数据库密码破解:
`1、编辑mysql配置文件vim /etc/my. cnf
添加一行: skip-grant-tables

[root@localhost]# vim /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
sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

2、重后服务
service mysqld restart

[root@localhost ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@localhost ~]#

3、验证登入
mysql

[root@localhost mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

mysql >  use mysql;

4、修改密码
use mysql;
update user set authentication_string = Password’123456’where Host = ‘localhost’ and User = ‘root’ ;

mysql > select * from mysql.user\G
mysql > update user set authentication_string = Password'123456'where Host = 'localhost' and User = 'root' ;

5、删除修改/etc/my.cnf中skip-grant-tables

[root@localhost]# vim /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
sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

6.重启服务

[root@localhost ~]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL. SUCCESS!
[root@localhost ~]#

7.验证

[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 5
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>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值