二进制部署MySQL

下载安装包

[root@localhost ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
--2022-06-29 02:12:05--  https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz [following]
--2022-06-29 02:14:22--  https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 23.44.151.164
Connecting to cdn.mysql.com (cdn.mysql.com)|23.44.151.164|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 666328842 (635M) [application/x-tar-gz]
Saving to: ‘mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz’

100%[=========================================================================================>] 666,328,842 26.3MB/s   in 23s    

2022-06-29 02:12:05 (27.6 MB/s) - ‘mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz’ saved [666328842/666328842]

创建用户

[root@localhost ~]# useradd -M -s /sbin/nologin -r mysql

安装依赖包

[root@localhost ~]# yum install -y ncurses-devel libaio-devel gcc gcc-c++ glibc cmake autoconf

解压MySQL压缩包

[root@localhost ~]# tar -xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# ln -s /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64/ /usr/local/mysql
[root@localhost ~]# ll /usr/local/mysql/
total 272
drwxr-xr-x.  2 root root    4096 Sep 14 15:42 bin
drwxr-xr-x.  2 root root      55 Sep 14 15:43 docs
drwxr-xr-x.  3 root root    4096 Sep 14 15:42 include
drwxr-xr-x.  5 root root     230 Sep 14 15:43 lib
-rw-r--r--.  1 7161 31415 259200 Jun  7 20:52 LICENSE
drwxr-xr-x.  4 root root      30 Sep 14 15:42 man
-rw-r--r--.  1 7161 31415    566 Jun  7 20:52 README
drwxr-xr-x. 28 root root    4096 Sep 14 15:43 share
drwxr-xr-x.  2 root root      90 Sep 14 15:43 support-files

将MySQL目录授权

# 授权MySQL目录
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql/
# 授权二进制包
[root@db01 /usr/local]# chown -R mysql.mysql mysql-5.7.35-linux-glibc2.12-x86_64/

MySQL数据库初始化

创建保存数据的目录

[root@localhost mysql]# mkdir /mysql_data
[root@localhost mysql]# chown -R mysql.mysql /mysql_data/

初始化

[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql_data
2022-06-29T07:59:12.785658Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-29T02:21:45.770442Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-06-29T02:21:45.030108Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-06-29T02:21:45.113597Z 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: a79a5fbd-1531-11ec-a40a-000c294d81ef.
2022-06-29T02:21:45.117014Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-06-29T02:21:46.480600Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-06-29T02:21:46.480683Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-06-29T02:21:46.481652Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-29T02:21:47.481417Z 1 [Note] A temporary password is generated for root@localhost: nWHw,xjom9Nr  // 默认的密码

编写配置文件

[root@localhost mysql]# vim /etc/my.cnf
[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/mysql_data
port=3306
socket=/usr/local/mysql/mysql.sock
character-set-server=utf8mb4
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/usr/local/mysql/mysql.sock
[client]
socket=/usr/local/mysql/mysql.sock

生成启动脚本,并启动mysql

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/init.d/mysqld 
[root@localhost mysql]# vim /etc/init.d/mysqld
basedir="/usr/local/mysql"   --搜索/basedir和/datadir 在=后面添加引号里的内容    
datadir="/mysql_data"

启动,并测试

[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
[root@localhost mysql]# ./bin/mysql -uroot -p"nWHw,xjom9Nr"
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. All rights reserved.

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> 

加入Systemd管理

#1.配置system管理MySQL
[root@localhost mysql]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld start
LimitNOFILE = 5000
 
#2.重新加载启动文件列表
[root@localhost mysql]# systemctl daemon-reload
[root@localhost ~]# systemctl enable mysqld
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl status mysqld
● mysql.service - MySQL Serverenabl
   Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-06-29 02:23:45 CST; 4s ago
     Docs: man:mysqld(8)
           https://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 1797 (mysqld)
   CGroup: /system.slice/mysql.service
           └─1797 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

Sep 29 02:23:45 localhost.localdomain systemd[1]: Started MySQL Server.
posted @ 2022-06-29 02:23  夏天的海  阅读(64)  评论(0)    收藏  举报