mysql进阶与密码破解


二进制部署mysql

安装依赖包
[root@localhost ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
从网络上下载mysql
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# ls
mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz


解压
[root@localhost src]# tar -xf /usr/local/src/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# mv /usr/local/mysql-5.7.38-linux-glibc2.12-x86_64/ /usr/local/mysql

用mysql的用户进行管理此服务
[root@localhost src]# useradd -rMs  /sbin/nologin mysql
[root@localhost src]#  chown -R mysql.mysql /usr/local/mysql/

配置环境变量
[root@localhost src]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@localhost src]# source /etc/profile.d/mysql.sh

创建数据存放目录
[root@localhost src]#  mkdir /opt/data
[root@localhost src]# chown -R mysql.mysql /opt/data

创建头文件
[root@localhost src]# ln -sv /usr/local/mysql/include /usr/include/mysql
'/usr/include/mysql/include' -> '/usr/local/mysql/include'

创建库文件
[root@localhost src]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# ldconfig 

导入man文档
[root@localhost src]# echo "MANDATORY_MANPATH  /usr/local/mysql/man" >> /etc/man_db.conf

初始化mysql
[root@localhost src]# mysqld --initialize --user mysql --datadir /opt/data
I6/wGYQgi8sP   //初始化完成后最后面就是密码
记住初始化的密码

生成服务的配置文件
[root@localhost src]# 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

安装 *ncurses-compat-libs* 
[root@localhost src]#  dnf -y install ncurses-compat-libs

将mysql服务加入到systemd进行控制
[root@localhost src]# cat /lib/systemd/system/mysqld.service
[Unit]
Description=mysql server daemon
After=network.target sshd-keygen.target
 
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP
 
[Install]
WantedBy=multi-user.target

重新加载
[root@localhost src]# systemctl daemon-reload 

重启mysql
[root@localhost src]# systemctl restart mysqld.service

查看端口
[root@localhost src]# ss -anlt    //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 src]# mysql -uroot -p
Enter password:   "刚刚初始化的密码"
mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

多表联查

查看liuyang的所有字段
mysql> select * from liuyang;
+----+-------+-----+-----+--------+------------+
| id | name  | age | sex | height | course_idd |
+----+-------+-----+-----+--------+------------+
|  1 | Dany  |  25 |   1 | 160    |          1 |
|  2 | Green |  25 |   1 | 158    |          2 |
|  3 | Henry |  23 |   2 | 185    |          1 |
|  4 | Jane  |  22 |   1 | 162    |          3 |
|  5 | Jim   |  24 |   2 | 175    |          2 |
|  6 | John  |  24 |   2 | 172    |          4 |
|  7 | Lily  |  22 |   1 | 165    |          4 |
|  8 | Susan |  23 |   1 | 170    |          5 |
|  9 | Tomas |  22 |   2 | 178    |          5 |
| 10 | Tom   |  23 |   2 | 165    |          5 |
+----+-------+-----+-----+--------+------------+
10 rows in set (0.00 sec)
查看tb_course的所有字段
mysql> select * from tb_course;
+----+-------------+
| id | course_name |
+----+-------------+
|  1 | Java        |
|  2 | MySQL       |
|  3 | Python      |
|  4 | Go          |
|  5 | C++         |
+----+-------------+
5 rows in set (0.00 sec)
查看两个表一起的笛卡尔积
mysql> select * from liuyang cross join tb_course;
+----+-------+-----+-----+--------+------------+----+-------------+
| id | name  | age | sex | height | course_idd | id | course_name |
+----+-------+-----+-----+--------+------------+----+-------------+
|  1 | Dany  |  25 |   1 | 160    |          1 |  1 | Java        |
|  1 | Dany  |  25 |   1 | 160    |          1 |  2 | MySQL       |
|  1 | Dany  |  25 |   1 | 160    |          1 |  3 | Python      |
|  1 | Dany  |  25 |   1 | 160    |          1 |  4 | Go          |
|  1 | Dany  |  25 |   1 | 160    |          1 |  5 | C++         |
|  2 | Green |  25 |   1 | 158    |          2 |  1 | Java        |
|  2 | Green |  25 |   1 | 158    |          2 |  2 | MySQL       |
|  2 | Green |  25 |   1 | 158    |          2 |  3 | Python      |
|  2 | Green |  25 |   1 | 158    |          2 |  4 | Go          |
|  2 | Green |  25 |   1 | 158    |          2 |  5 | C++         |
|  3 | Henry |  23 |   2 | 185    |          1 |  1 | Java        |
|  3 | Henry |  23 |   2 | 185    |          1 |  2 | MySQL       |
|  3 | Henry |  23 |   2 | 185    |          1 |  3 | Python      |
|  3 | Henry |  23 |   2 | 185    |          1 |  4 | Go          |
|  3 | Henry |  23 |   2 | 185    |          1 |  5 | C++         |
|  4 | Jane  |  22 |   1 | 162    |          3 |  1 | Java        |
|  4 | Jane  |  22 |   1 | 162    |          3 |  2 | MySQL       |
|  4 | Jane  |  22 |   1 | 162    |          3 |  3 | Python      |
|  4 | Jane  |  22 |   1 | 162    |          3 |  4 | Go          |
|  4 | Jane  |  22 |   1 | 162    |          3 |  5 | C++         |
|  5 | Jim   |  24 |   2 | 175    |          2 |  1 | Java        |
|  5 | Jim   |  24 |   2 | 175    |          2 |  2 | MySQL       |
|  5 | Jim   |  24 |   2 | 175    |          2 |  3 | Python      |
|  5 | Jim   |  24 |   2 | 175    |          2 |  4 | Go          |
|  5 | Jim   |  24 |   2 | 175    |          2 |  5 | C++         |
|  6 | John  |  24 |   2 | 172    |          4 |  1 | Java        |
|  6 | John  |  24 |   2 | 172    |          4 |  2 | MySQL       |
|  6 | John  |  24 |   2 | 172    |          4 |  3 | Python      |
|  6 | John  |  24 |   2 | 172    |          4 |  4 | Go          |
|  6 | John  |  24 |   2 | 172    |          4 |  5 | C++         |
|  7 | Lily  |  22 |   1 | 165    |          4 |  1 | Java        |
|  7 | Lily  |  22 |   1 | 165    |          4 |  2 | MySQL       |
|  7 | Lily  |  22 |   1 | 165    |          4 |  3 | Python      |
|  7 | Lily  |  22 |   1 | 165    |          4 |  4 | Go          |
|  7 | Lily  |  22 |   1 | 165    |          4 |  5 | C++         |
|  8 | Susan |  23 |   1 | 170    |          5 |  1 | Java        |
|  8 | Susan |  23 |   1 | 170    |          5 |  2 | MySQL       |
|  8 | Susan |  23 |   1 | 170    |          5 |  3 | Python      |
|  8 | Susan |  23 |   1 | 170    |          5 |  4 | Go          |
|  8 | Susan |  23 |   1 | 170    |          5 |  5 | C++         |
|  9 | Tomas |  22 |   2 | 178    |          5 |  1 | Java        |
|  9 | Tomas |  22 |   2 | 178    |          5 |  2 | MySQL       |
|  9 | Tomas |  22 |   2 | 178    |          5 |  3 | Python      |
|  9 | Tomas |  22 |   2 | 178    |          5 |  4 | Go          |
|  9 | Tomas |  22 |   2 | 178    |          5 |  5 | C++         |
| 10 | Tom   |  23 |   2 | 165    |          5 |  1 | Java        |
| 10 | Tom   |  23 |   2 | 165    |          5 |  2 | MySQL       |
| 10 | Tom   |  23 |   2 | 165    |          5 |  3 | Python      |
| 10 | Tom   |  23 |   2 | 165    |          5 |  4 | Go          |
| 10 | Tom   |  23 |   2 | 165    |          5 |  5 | C++         |
+----+-------+-----+-----+--------+------------+----+-------------+
50 rows in set (0.00 sec)
查看liuyang表下的course_idd和tb_course.id相同的数据
mysql> select * from tb_course cross join liuyang where liuyang.course_idd =tb_course.id;
+----+-------------+----+-------+-----+-----+--------+------------+
| id | course_name | id | name  | age | sex | height | course_idd |
+----+-------------+----+-------+-----+-----+--------+------------+
|  1 | Java        |  1 | Dany  |  25 |   1 | 160    |          1 |
|  2 | MySQL       |  2 | Green |  25 |   1 | 158    |          2 |
|  1 | Java        |  3 | Henry |  23 |   2 | 185    |          1 |
|  3 | Python      |  4 | Jane  |  22 |   1 | 162    |          3 |
|  2 | MySQL       |  5 | Jim   |  24 |   2 | 175    |          2 |
|  4 | Go          |  6 | John  |  24 |   2 | 172    |          4 |
|  4 | Go          |  7 | Lily  |  22 |   1 | 165    |          4 |
|  5 | C++         |  8 | Susan |  23 |   1 | 170    |          5 |
|  5 | C++         |  9 | Tomas |  22 |   2 | 178    |          5 |
|  5 | C++         | 10 | Tom   |  23 |   2 | 165    |          5 |
+----+-------------+----+-------+-----+-----+--------+------------+
10 rows in set (0.00 sec)
查看两个表的总数据且liuyang.age不等于25的数据
mysql> select * from liuyang cross join tb_course where liuyang.age !=25;
+----+-------+-----+-----+--------+------------+----+-------------+
| id | name  | age | sex | height | course_idd | id | course_name |
+----+-------+-----+-----+--------+------------+----+-------------+
|  3 | Henry |  23 |   2 | 185    |          1 |  1 | Java        |
|  3 | Henry |  23 |   2 | 185    |          1 |  2 | MySQL       |
|  3 | Henry |  23 |   2 | 185    |          1 |  3 | Python      |
|  3 | Henry |  23 |   2 | 185    |          1 |  4 | Go          |
|  3 | Henry |  23 |   2 | 185    |          1 |  5 | C++         |
|  4 | Jane  |  22 |   1 | 162    |          3 |  1 | Java        |
|  4 | Jane  |  22 |   1 | 162    |          3 |  2 | MySQL       |
|  4 | Jane  |  22 |   1 | 162    |          3 |  3 | Python      |
|  4 | Jane  |  22 |   1 | 162    |          3 |  4 | Go          |
|  4 | Jane  |  22 |   1 | 162    |          3 |  5 | C++         |
|  5 | Jim   |  24 |   2 | 175    |          2 |  1 | Java        |
|  5 | Jim   |  24 |   2 | 175    |          2 |  2 | MySQL       |
|  5 | Jim   |  24 |   2 | 175    |          2 |  3 | Python      |
|  5 | Jim   |  24 |   2 | 175    |          2 |  4 | Go          |
|  5 | Jim   |  24 |   2 | 175    |          2 |  5 | C++         |
|  6 | John  |  24 |   2 | 172    |          4 |  1 | Java        |
|  6 | John  |  24 |   2 | 172    |          4 |  2 | MySQL       |
|  6 | John  |  24 |   2 | 172    |          4 |  3 | Python      |
|  6 | John  |  24 |   2 | 172    |          4 |  4 | Go          |
|  6 | John  |  24 |   2 | 172    |          4 |  5 | C++         |
|  7 | Lily  |  22 |   1 | 165    |          4 |  1 | Java        |
|  7 | Lily  |  22 |   1 | 165    |          4 |  2 | MySQL       |
|  7 | Lily  |  22 |   1 | 165    |          4 |  3 | Python      |
|  7 | Lily  |  22 |   1 | 165    |          4 |  4 | Go          |
|  7 | Lily  |  22 |   1 | 165    |          4 |  5 | C++         |
|  8 | Susan |  23 |   1 | 170    |          5 |  1 | Java        |
|  8 | Susan |  23 |   1 | 170    |          5 |  2 | MySQL       |
|  8 | Susan |  23 |   1 | 170    |          5 |  3 | Python      |
|  8 | Susan |  23 |   1 | 170    |          5 |  4 | Go          |
|  8 | Susan |  23 |   1 | 170    |          5 |  5 | C++         |
|  9 | Tomas |  22 |   2 | 178    |          5 |  1 | Java        |
|  9 | Tomas |  22 |   2 | 178    |          5 |  2 | MySQL       |
|  9 | Tomas |  22 |   2 | 178    |          5 |  3 | Python      |
|  9 | Tomas |  22 |   2 | 178    |          5 |  4 | Go          |
|  9 | Tomas |  22 |   2 | 178    |          5 |  5 | C++         |
| 10 | Tom   |  23 |   2 | 165    |          5 |  1 | Java        |
| 10 | Tom   |  23 |   2 | 165    |          5 |  2 | MySQL       |
| 10 | Tom   |  23 |   2 | 165    |          5 |  3 | Python      |
| 10 | Tom   |  23 |   2 | 165    |          5 |  4 | Go          |
| 10 | Tom   |  23 |   2 | 165    |          5 |  5 | C++         |
+----+-------+-----+-----+--------+------------+----+-------------+
40 rows in set (0.00 sec)
查看两个表的所有数据且liuyang.age大于等于24。
mysql> select * from tb_course cross join liuyang where (liuyang.age >= 24);
+----+-------------+----+-------+-----+-----+--------+------------+
| id | course_name | id | name  | age | sex | height | course_idd |
+----+-------------+----+-------+-----+-----+--------+------------+
|  1 | Java        |  1 | Dany  |  25 |   1 | 160    |          1 |
|  1 | Java        |  2 | Green |  25 |   1 | 158    |          2 |
|  1 | Java        |  5 | Jim   |  24 |   2 | 175    |          2 |
|  1 | Java        |  6 | John  |  24 |   2 | 172    |          4 |
|  2 | MySQL       |  1 | Dany  |  25 |   1 | 160    |          1 |
|  2 | MySQL       |  2 | Green |  25 |   1 | 158    |          2 |
|  2 | MySQL       |  5 | Jim   |  24 |   2 | 175    |          2 |
|  2 | MySQL       |  6 | John  |  24 |   2 | 172    |          4 |
|  3 | Python      |  1 | Dany  |  25 |   1 | 160    |          1 |
|  3 | Python      |  2 | Green |  25 |   1 | 158    |          2 |
|  3 | Python      |  5 | Jim   |  24 |   2 | 175    |          2 |
|  3 | Python      |  6 | John  |  24 |   2 | 172    |          4 |
|  4 | Go          |  1 | Dany  |  25 |   1 | 160    |          1 |
|  4 | Go          |  2 | Green |  25 |   1 | 158    |          2 |
|  4 | Go          |  5 | Jim   |  24 |   2 | 175    |          2 |
|  4 | Go          |  6 | John  |  24 |   2 | 172    |          4 |
|  5 | C++         |  1 | Dany  |  25 |   1 | 160    |          1 |
|  5 | C++         |  2 | Green |  25 |   1 | 158    |          2 |
|  5 | C++         |  5 | Jim   |  24 |   2 | 175    |          2 |
|  5 | C++         |  6 | John  |  24 |   2 | 172    |          4 |
+----+-------------+----+-------+-----+-----+--------+------------+
20 rows in set (0.00 sec)
查看liuyang.height的平均值且身高小于172并且性别为1的所有数据。
mysql> select avg(liuyang.height) from liuyang cross join tb_course where liuyyang.height < 172 and liuyang.sex = 1;
+---------------------+
| avg(liuyang.height) |
+---------------------+
|                 163 |
+---------------------+
1 row in set (0.00 sec)

密码破解

进入mysql的/etc/my.cnf文件中
skip-grant-tables
添加权限 skip-grant-tables
重启mysql

systemctl  restart  mysqld.service 

更新mysql这个数据库下的user表设置密码字段判断user=root并且host=localhost这行记录

mysql -e "update mysql.user set authentication_string=password('020524') where user = 'root' and 'host' = 'localhost'; "

删除刚刚配置文件中的跳过权限,重启mysql服务
使用更新的密码进入mysql中

[root@node1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.39 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.
posted @ 2022-07-27 22:07  Tqing  阅读(47)  评论(0编辑  收藏  举报