MySql二进制部署

MySql二进制部署

二进制格式MySQL安装

# 下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels
[root@localhost src]# ls debug/
[root@localhost src]# ls kernels/
[root@localhost src]# 
[root@localhost src]# 
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

# 创建用户和组
[root@localhost src]# useradd -r -M -s /sbin/nologin mysql
[root@localhost src]# id mysql
uid=994(mysql) gid=991(mysql) groups=991(mysql)
# 解压软件
[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]# 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]# chown -R mysql.mysql mysql
[root@localhost 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 Mar 22 19:07 lib64
drwxr-xr-x. 2 root  root    6 Jun 21  2021 libexec
drwxr-xr-x  9 mysql mysql 129 Jun 28 18:41 mysql
drwxr-xr-x. 2 root  root    6 Jun 21  2021 sbin
drwxr-xr-x. 5 root  root   49 Mar 22 19:07 share
drwxr-xr-x. 2 root  root    6 Jun 21  2021 src
[root@localhost local]# ls mysql/
bin  docs  include  lib  LICENSE  man  README  share  support-files

# 添加环境变量
[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]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost local]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost local]# ldconfig
[root@localhost local]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/local/mysql/man
# 建立数据存放目录
[root@localhost local]# mkdir -p /opt/data
[root@localhost local]# chown -R mysql.mysql /opt/data
[root@localhost local]# ll /opt/
total 0
drwxr-xr-x 2 mysql mysql 6 Jun 28 19:08 data
# 初始化数据库
# 数据库临时密码会显示在最后一行
[root@localhost local]# mysqld --initialize --user mysql --datadir /opt/data
2022-06-28T11:12:40.556649Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-28T11:12:40.789657Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-06-28T11:12:40.842592Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-06-28T11:12:40.912832Z 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: 39c10cea-f6d3-11ec-a51d-000c29399951.
2022-06-28T11:12:40.915387Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-06-28T11:12:41.740869Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-06-28T11:12:41.740908Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-06-28T11:12:41.741698Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-28T11:12:42.008101Z 1 [Note] A temporary password is generated for root@localhost: /lf(K=Gkw5x:
# 生成配置文件
[root@localhost local]# 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
sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# 启动MySQL服务
[root@localhost local]# vim mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/opt/data
[root@localhost local]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost local]# 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                     [::]:*                    

# 登录MySQL
[root@localhost local]# dnf -y install ncurses-compat-libs
[root@localhost local]# mysql -uroot -p'/lf(K=Gkw5x:'
mysql> set password = password('runtime123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye
[root@localhost local]# /usr/local/mysql/support-files/mysql.server stop

# 配置服务控制
[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service

[Unit]
Documentation=mysqld 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 $MAINPID

[Install]
WantedBy=multi-user.target
~                               
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable --now mysqld
[root@localhost ~]# systemctl status mysqld.service
● mysqld.service
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-06-28 20:06:27 CST; 5s ago
  Process: 2605 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=exited, status=0/SUC>
 Main PID: 2618 (mysqld_safe)
    Tasks: 28 (limit: 11216)
   Memory: 179.7M
   CGroup: /system.slice/mysqld.service
           ├─2618 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/my>
           └─2808 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin->

Jun 28 20:06:26 localhost.localdomain systemd[1]: Starting mysqld.service...
Jun 28 20:06:27 localhost.localdomain mysql.server[2605]: Starting MySQL. SUCCESS!
Jun 28 20:06:27 localhost.localdomain systemd[1]: Started mysqld.service.
# 配置MySQL免密登录
[root@localhost ~]# vim .my.cnf
[client]
user = root
password = runtime123
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
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 ~]# rm -f .my.cnf

MySQL密码破解

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

  1. 修改配置文件,加入skip-grant-tables
  2. 重启mysql
  3. 修改密码
  4. 恢复配置文件,删除加入的内容
  5. 重启mysql
  6. 验证新密码
[root@localhost ~]# vim /etc/my.cnf
skip-grant-tables		//添加此行

[root@localhost ~]# systemctl restart mysqld
[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> 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('123456') where User = 'root' and Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> quit
[root@localhost ~]# vim /etc/my.cnf
skip-grant-tables		//删除此行

[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# mysql -uroot -p'123456'
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> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值