二进制格式mysql安装和密码破解
文章目录
- 二进制格式mysql安装和密码破解
- 一. 二进制安装mysql
- 1. 下载二进制格式的[mysql软件包](https://downloads.mysql.com/archives/community/)
- 2. 创建用户,下载完成后上传到/usr/src/目录下,解压
- 3. 修改文件属组
- 4. 添加环境变量,lib库文件,头文件和man文档
- 5. 建立数据存放目录
- 6. 初始化数据库,并保存密码
- 7. 生成配置文件
- 8. 配置服务启动脚本
- 9. 启动mysql
- 10. 修改密码,缺少库文件
- 11. 配置service文件,设置开机自启,关闭selinux
- 二. mysql配置文件
- 2.1 配置.my.cnf文件登录mysql不用输入密码
- 2.2 mysql常用配置文件参数
- 三. 破解mysql密码
- 1. 修改配置文件
- 2.重启mysql,进入数据库查看密码
- 3. 修改密码
- 4. 修改配置文件,删除此行skip-grant-tables,重启mysql
- 5. 验证
一. 二进制安装mysql
1. 下载二进制格式的mysql软件包
2. 创建用户,下载完成后上传到/usr/src/目录下,解压
[root@SYL6 ~]# cd /usr/src/
[root@SYL6 src]# ls
debug kernels mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@SYL6 src]# useradd -r -M -s /sbin/nologin mysql
[root@SYL6 src]# id mysql
uid=995(mysql) gid=992(mysql) groups=992(mysql)
[root@SYL6 src]#
[root@SYL6 src]# ls /usr/local/
bin etc games include lib lib64 libexec sbin share src
[root@SYL6 src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@SYL6 src]# cd /usr/local/
[root@SYL6 local]# ls
bin include libexec share
etc lib mysql-5.7.37-linux-glibc2.12-x86_64 src
games lib64 sbin
[root@SYL6 local]# mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql
[root@SYL6 local]# ls
bin games lib libexec sbin src
etc include lib64 mysql share
[root@SYL6 local]#
3. 修改文件属组
[root@SYL6 local]# ll
total 0
drwxr-xr-x. 2 root root 6 Jun 21 2021 bin
drwxr-xr-x. 2 root root 6 Jun 21 2021 etc
drwxr-xr-x. 2 root root 6 Jun 21 2021 games
drwxr-xr-x. 2 root root 6 Jun 21 2021 include
drwxr-xr-x. 2 root root 6 Jun 21 2021 lib
drwxr-xr-x. 3 root root 17 May 13 18:53 lib64
drwxr-xr-x. 2 root root 6 Jun 21 2021 libexec
drwxr-xr-x. 9 root root 129 Jun 28 15:03 mysql
drwxr-xr-x. 2 root root 6 Jun 21 2021 sbin
drwxr-xr-x. 5 root root 49 May 13 18:53 share
drwxr-xr-x. 2 root root 6 Jun 21 2021 src
[root@SYL6 local]# chown -R mysql.mysql mysql
[root@SYL6 local]# ll
total 0
drwxr-xr-x. 2 root root 6 Jun 21 2021 bin
drwxr-xr-x. 2 root root 6 Jun 21 2021 etc
drwxr-xr-x. 2 root root 6 Jun 21 2021 games
drwxr-xr-x. 2 root root 6 Jun 21 2021 include
drwxr-xr-x. 2 root root 6 Jun 21 2021 lib
drwxr-xr-x. 3 root root 17 May 13 18:53 lib64
drwxr-xr-x. 2 root root 6 Jun 21 2021 libexec
drwxr-xr-x. 9 mysql mysql 129 Jun 28 15:03 mysql
4. 添加环境变量,lib库文件,头文件和man文档
1.环境变量
[root@SYL6 mysql]# pwd
/usr/local/mysql
[root@SYL6 mysql]# ls
LICENSE bin include man support-files
README docs lib share
[root@SYL6 mysql]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@SYL6 mysql]# source /etc/profile.d/mysql.sh
[root@SYL6 mysql]# which mysql
/usr/local/mysql/bin/mysql
[root@SYL6 mysql]#
2.lib库文件
[root@SYL6 mysql]# ls
LICENSE bin include man support-files
README docs lib share
[root@SYL6 mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@SYL6 mysql]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@SYL6 mysql]# ldconfig
[root@SYL6 mysql]#
3.头文件
[root@SYL6 mysql]# ls
LICENSE bin include man support-files
README docs lib share
[root@SYL6 mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@SYL6 mysql]#
4.man文档
[root@SYL6 mysql]# ls
LICENSE bin include man support-files
README docs lib share
[root@SYL6 mysql]# vim /etc/man_db.conf
[root@SYL6 mysql]# cat /etc/man_db.conf |grep mysql
MANDATORY_MANPATH /usr/local/mysql/man
[root@SYL6 mysql]#
5. 建立数据存放目录
[root@SYL6 ~]# mkdir -p /opt/data
[root@SYL6 ~]# ll /opt/
total 0
drwxr-xr-x. 2 root root 6 Jun 28 15:29 data
[root@SYL6 ~]# chown -R mysql.mysql /opt/data/
[root@SYL6 ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jun 28 15:29 data
[root@SYL6 ~]#
6. 初始化数据库,并保存密码
--initialize //初始化
--user mysql //用mysql用户
--datadir /opt/data //数据放在位置/opt/data
[root@SYL6 ~]# mysqld --initialize --user mysql --datadir /opt/data
2022-06-28T07:32:11.535377Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-28T07:32:17.891731Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-06-28T07:32:19.526395Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-06-28T07:32:20.286728Z 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: 71a59937-f6b4-11ec-a34e-000c296eeaef.
2022-06-28T07:32:20.301303Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-06-28T07:32:21.102238Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-06-28T07:32:21.102257Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-06-28T07:32:21.102767Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-28T07:32:21.268224Z 1 [Note] A temporary password is generated for root@localhost: TuJ5l(6t4sl3
[root@SYL6 ~]#
临时密码
[root@SYL6 ~]# echo 'TuJ5l(6t4sl3' > passwd
[root@SYL6 ~]# cat passwd
TuJ5l(6t4sl3
[root@SYL6 ~]#
7. 生成配置文件
[root@SYL6 ~]# vim /etc/my.cnf
[root@SYL6 ~]# cat /etc/my.cnf
[mysqld] //mysql主程序
basedir = /usr/local/mysql //安装位置
datadir = /opt/data //数据存放位置
socket = /tmp/mysql.sock //套接字存放位置
port = 3306 //端口号
pid-file = /opt/data/mysql.pid //进程id
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@SYL6 ~]#
8. 配置服务启动脚本
[root@SYL6 support-files]# pwd
/usr/local/mysql/support-files
[root@SYL6 support-files]# ls
magic mysql-log-rotate mysql.server mysqld_multi.server
[root@SYL6 support-files]# cp mysql.server mysqld
[root@SYL6 support-files]# chown -R mysql.mysql mysqld
[root@SYL6 support-files]# ll
total 36
-rw-r--r--. 1 mysql mysql 773 Nov 30 2021 magic
-rwxr-xr-x. 1 mysql mysql 894 Nov 30 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 Nov 30 2021 mysql.server
-rwxr-xr-x. 1 mysql mysql 10576 Jun 28 15:51 mysqld
-rwxr-xr-x. 1 mysql mysql 1061 Nov 30 2021 mysqld_multi.server
[root@SYL6 support-files]#
[root@SYL6 support-files]# vim mysqld
[root@SYL6 support-files]# cat mysqld
basedir=/usr/local/mysql //数据库安装位置 //添加此行
datadir=/opt/data //数据存放位置 //添加此行
9. 启动mysql
[root@SYL6 ~]# ls /usr/local/mysql/
LICENSE bin include man support-files
README docs lib share
[root@SYL6 ~]# ls /usr/local/mysql/support-files/mysqld
/usr/local/mysql/support-files/mysqld
[root@SYL6 ~]# /usr/local/mysql/support-files/mysqld start
Starting MySQL.Logging to '/opt/data/SYL6.err'.
................... SUCCESS!
[root@SYL6 ~]# 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 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
[root@SYL6 ~]#
10. 修改密码,缺少库文件
[root@SYL6 ~]# cat passwd
TuJ5l(6t4sl3
[root@SYL6 ~]# mysql -uroot -p'TuJ5l(6t4sl3'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
1.登录不成功,安装软件
[root@SYL6 ~]# yum provides libncurses.so.5
Failed to set locale, defaulting to C.UTF-8
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Last metadata expiration check: 1:11:53 ago on Tue Jun 28 14:48:31 2022.
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses
...: compatibility libraries
Repo : base
Matched from:
Provide : libncurses.so.5
[root@SYL6 ~]# yum -y install ncurses-compat-libs
2.设置密码
[root@SYL6 ~]# mysql -uroot -p'TuJ5l(6t4sl3'
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('run123!');
Query OK, 0 rows affected, 1 warning (0.11 sec)
mysql> quit
[root@SYL6 ~]# mysql -uroot -p'run123!'
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> quit
Bye
[root@SYL6 ~]#
11. 配置service文件,设置开机自启,关闭selinux
1.关闭selinux
[root@SYL6 ~]# setenforce 0
[root@SYL6 ~]# ls /etc/selinux/
config semanage.conf targeted
[root@SYL6 ~]# vim /etc/selinux/config
[root@SYL6 ~]# cat /etc/selinux/config |grep disabled
# disabled - No SELinux policy is loaded.
SELINUX=disabled
[root@SYL6 ~]#
2.配置service文件,设置开机自启
[root@SYL6 ~]# cd /usr/lib/systemd/system
[root@SYL6 system]# cp sshd.service mysqld.service
[root@SYL6 system]# vim mysqld.service
[root@SYL6 system]# cat mysqld.service
[Unit]
Description=mysqld 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@SYL6 system]#
[root@SYL6 ~]# cd /usr/lib/systemd/system
[root@SYL6 ~]# cd /usr/lib/systemd/system
[root@SYL6 system]# vim mysqld.service
[root@SYL6 system]# systemctl daemon-reload
[root@SYL6 system]# systemctl start mysqld
[root@SYL6 system]# systemctl enable --now mysqld.service
[root@SYL6 system]# systemctl status mysqld.service
● mysqld.service - mysqld server daemon
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enable>
Active: active (running) since Tue 2022-06-28 16:30:02 CST; 1m>
Main PID: 1025 (mysqld_safe)
Tasks: 28 (limit: 23502)
Memory: 218.5M
CGroup: /system.slice/mysqld.service
├─1025 /bin/sh /usr/local/mysql/bin/mysqld_safe --data>
└─1243 /usr/local/mysql/bin/mysqld --basedir=/usr/loca>
Jun 28 16:28:54 SYL6 systemd[1]: Starting mysqld server daemon...
Jun 28 16:30:02 SYL6 mysqld[1000]: Starting MySQL................>
Jun 28 16:30:02 SYL6 systemd[1]: Started mysqld server daemon.
[root@SYL6 system]# cd
[root@SYL6 ~]# 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 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
[root@SYL6 ~]# mysql -uroot -p'run123!';
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@SYL6 ~]#
二. mysql配置文件
mysql的配置文件为/etc/my.cnf
配置文件查找次序:若在多个配置文件中均有设定,则最后找到的最终生效
/etc/my.cnf --> /etc/mysql/my.cnf --> --default-extra-file=/PATH/TO/CONF_FILE --> ~/.my.cnf
2.1 配置.my.cnf文件登录mysql不用输入密码
[root@SYL6 ~]# ls -a
. .bash_logout .config .tcshrc
.. .bash_profile .cshrc .viminfo
.bash_history .bashrc .mysql_history anaconda-ks.cfg
[root@SYL6 ~]# vim .my.cnf
[root@SYL6 ~]# cat .my.cnf
[client]
user = root
password = run123!
[root@SYL6 ~]# mysql
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> quit
Bye
[root@SYL6 ~]#
在/etc/my.cnf 加一行,重启,免密
skip-grant-tables
2.2 mysql常用配置文件参数
参数 | 说明 |
port = 3306 | 设置监听端口 |
socket = /tmp/mysql.sock | 指定套接字文件位置 |
basedir = /usr/local/mysql | 指定MySQL的安装路径 |
datadir = /data/mysql | 指定MySQL的数据存放路径 |
pid-file = /data/mysql/mysql.pid | 指定进程ID文件存放路径 |
user = mysql | 指定MySQL以什么用户的身份提供服务 |
skip-name-resolve | 禁止MySQL对外部连接进行DNS解析 使用这一选项可以消除MySQL进行DNS解析的时间。 若开启该选项,则所有远程主机连接授权都要使用IP地址方 式否则MySQL将无法正常处理连接请求 |
三. 破解mysql密码
破解mysql密码(root账户)
1.修改配置文件
vim /etc/my.cnf
skip-grant-tables 添加一行
2.重启mysql
systemctl restart mysqld
3.进入数据库修改密码
update user set authentication_string = password('run123456') where User = 'root' and Host = 'localhost';
4.修改配置文件
删除此行skip-grant-tables
5.重启mysql
systemctl restart mysqld
6.验证
1. 修改配置文件
[root@SYL6 ~]# vim /etc/my.cnf
[root@SYL6 ~]# 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
#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@SYL6 ~]#
2.重启mysql,进入数据库查看密码
[root@SYL6 ~]# systemctl restart mysqld
[root@SYL6 ~]#
[root@SYL6 ~]# mysql
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> 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>
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
mysql> select * from user\G
*************************** 1. row ***************************
Host: localhost
User: root
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string: *67FD196E4F71F1161F065970DE937AD3F297FCDC
password_expired: N
password_last_changed: 2022-06-28 16:02:32
password_lifetime: NULL
account_locked: N
*************************** 2. row ***************************
3. 修改密码
mysql> update user set authentication_string = password('run123456') where User = 'root' and Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.66 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> select * from user\G
*************************** 1. row ***************************
Host: localhost
User: root
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string: *9DA1D1D6C499848035E25E8853F05C7D8A9F6A79
password_expired: N
password_last_changed: 2022-06-28 16:02:32
4. 修改配置文件,删除此行skip-grant-tables,重启mysql
[root@SYL6 ~]# vim /etc/my.cnf
[root@SYL6 ~]# 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@SYL6 ~]# systemctl restart mysqld
[root@SYL6 ~]#
5. 验证
[root@SYL6 ~]# mysql -uroot -p'run123456'
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@SYL6 ~]#