首页 > 数据库 >二进制部署mysql

二进制部署mysql

时间:2023-01-01 20:22:52浏览次数:43  
标签:二进制 root 部署 mysqld usr mysql node2 local

二进制部署mysql

目录

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

#下载地址mysql  选择linux 64位
https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
#将下载的软件包通过xftp工具传输
#使用md5sum 对文件进行检测  查看是否一致
[root@node2 ~]# ls
anaconda-ks.cfg  mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
[root@node2 ~]# md5sum mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz 
79b971fc3e3368f2a1e07fbafae0b914  mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
[root@node2 ~]# 

1.2 创建用户mysql

#useradd -r表示为系统用户  nologin表示不允许登录 -u指定用户的uid号为306 用户是mysql
[root@node2 ~]# useradd -r -M -s /sbin/nologin -u 306 mysql
[root@node2 ~]# id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)

1.3 解压软件包到/usr/local

#tar xf解压至/usr/local
[root@node2 ~]# tar xf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@node2 ~]# cd /usr/local/
[root@node2 local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.39-linux-glibc2.12-x86_64  sbin  share  src
[root@node2 local]#
#给mysql-5.7.39-linux-glibc2.12-x86_64目录做个软链接  可以直接使用mysql来查找
[root@node2 local]# ln -s /usr/local/mysql-5.7.39-linux-glibc2.12-x86_64 /usr/local/mysql
[root@node2 local]# ll
...
lrwxrwxrwx. 1 root root  46 Dec 29 14:16 mysql -> /usr/local/mysql-5.7.39-linux-glibc2.12-x86_64
drwxr-xr-x. 9 root root 129 Dec 29 14:13 mysql-5.7.39-linux-glibc2.12-x86_64
...

1.4 修改mysql目录的属主组

[root@node2 local]# chown -R mysql.mysql /usr/local/mysql*
[root@node2 local]# ll
...
lrwxrwxrwx. 1 mysql mysql  46 Dec 29 14:16 mysql -> /usr/local/mysql-5.7.39-linux-glibc2.12-x86_64
drwxr-xr-x. 9 mysql mysql 129 Dec 29 14:13 mysql-5.7.39-linux-glibc2.12-x86_64
...

1.5 添加环境变量

#echo写入环境变量到/etc/profile.d/mysqld.sh
[root@node2 local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysqld.sh
#source读取
[root@node2 local]# source /etc/profile.d/mysqld.sh 
[root@node2 local]#
[root@node2 local]# which mysql
/usr/local/mysql/bin/mysql
#将mysql里的include指向 /usr/include/mysqld里    后不要带左斜杠
[root@node2 local]# ln -s /usr/local/mysql/include /usr/include/mysqld
#有lib库文件需要让我们知道在哪  在/etc/ld.so.conf.d/mysqld.conf写入/usr/local/mysql/lib
[root@node2 local]# vi /etc/ld.so.conf.d/mysqld.conf
/usr/local/mysql/lib
#ldconfig执行读取
[root@node2 local]# ldconfig 
#man文档修改/etc/man_db.conf 
[root@node2 local]# vi /etc/man_db.conf 
#添加一行/usr/local/mysql/man
...
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/mysql/man
...

1.6 建立数据存放的目录data

[root@node2 local]# mkdir -p /opt/data
[root@node2 local]# chown -R mysql.mysql /opt/data/
[root@node2 local]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Dec 29 14:37 data
[root@node2 local]# 

1.7 初始化数据库

#使用的是安装目录下的mysqld程序--initialize表示初始化--user用mysql用户来初始化--datadir数据存放的位置目录
[root@node2 local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2022-12-29T06:43:06.574811Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-12-29T06:43:06.735044Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-12-29T06:43:06.772314Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-12-29T06:43:06.834239Z 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: 0d4283e0-8744-11ed-9ee3-000c29f103f2.
2022-12-29T06:43:06.834958Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-12-29T06:43:06.944819Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-12-29T06:43:06.944833Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-12-29T06:43:06.945218Z 0 [Warning] CA certificate ca.pem is self signed.
#temporary password表示临时密码 需要保存记住只能使用一次
2022-12-29T06:43:07.011663Z 1 [Note] A temporary password is generated for root@localhost: PH!InwWOy8tU
[root@node2 local]#
#将临时密码保存出来
[root@node2 local]# echo 'PH!InwWOy8tU' > pass
[root@node2 local]# cat pass 
PH!InwWOy8tU

1.8 生成配置文件

#如果有my.cnf文件 将其备份一份 再清空去修改
[root@node2 local]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@node2 local]# cp /etc/my.cnf /etc/my.cnf_1229
#修改配置文件my.cnf
[root@node2 etc]# vi /etc/my.cnf
#指mysqld程序
[mysqld]
#basedir指安装目录
basedir = /usr/local/mysql
#datadir数据存放位置
datadir = /opt/data
#套接字文件位置
socket = /tmp/mysql.sock
#port端口号
port = 3306
#pid文件存放位置
pid-file = /opt/data/mysql.pid
#user用户
user = mysql
#跳过名称解析 通过内网地址访问
skip-name-resolve
skip-grant-tables

1.9 配置服务启动脚本启动开机自启mysql

#在安装目录下的support-files支持文件 里面的mysql.server就是用来启动 是一个脚本文件
[root@node2 etc]# cd /usr/local/mysql
[root@node2 mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@node2 mysql]# cd support-files/
[root@node2 support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@node2 support-files]# file mysql.server 
mysql.server: POSIX shell script, ASCII text executable
#填写安装位置和数据存放位置
[root@node2 support-files]# vim mysql.server 
...
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/usr/local/mysql
datadir=/opt/data
...
#start启动mysql.server
[root@node2 support-files]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/opt/data/node2.err'.
 SUCCESS! 
[root@node2 support-files]# 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                       [::]:*                      
[root@node2 support-files]#
#将system/sshd.service文件复制成system/mysqld.service文件 再去编辑
[root@node2 ~]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/mysqld.service
[root@node2 ~]# vim /usr/lib/systemd/system/mysqld.service

[Unit]
Description=mysqld server daemon
After=network.target 

[Service]
Type=forking
#设置启动start
ExecStart=/usr/local/mysql/support-files/mysql.server start
#设置停止stop
ExecStop=/usr/local/mysql/support-files/mysql.server stop

[Install]
WantedBy=multi-user.target
#重新加载服务的配置文件
[root@node2 ~]# systemctl daemon-reload
[root@node2 ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@node2 ~]# 
#设置开机自启动
[root@node2 ~]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
#active (running) 状态启动
[root@node2 ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-12-29 15:31:07 CST; 43s left
  Process: 985 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=exited, status=0/SUCCESS)
...
[root@node2 ~]# 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                       [::]:*                      
[root@node2 ~]# 

1.10 使用临时密码登录并修改密码

#安装libncurses.so.5 
[root@node2 ~]# yum provides libncurses.so.5 
Last metadata expiration check: 1:47:21 ago on Thu 29 Dec 2022 01:49:44 PM CST.
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : baseos
Matched from:
Provide    : libncurses.so.5

ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : baseos
Matched from:
Provide    : libncurses.so.5
[root@node2 ~]# yum -y install ncurses-compat-libs
Last metadata expiration check: 1:48:27 ago on Thu 29 Dec 2022 01:49:44 PM CST.
Dependencies resolved.
============================================================================================================
...
Complete!
#使用临时密码登录
[root@node2 ~]# mysql -uroot -p'PH!InwWOy8tU'
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.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.

mysql> 
#修改密码
mysql> set password = password('mysql0917!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@node2 ~]# mysql -uroot -pmysql0917!
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 4
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.

mysql> 

标签:二进制,root,部署,mysqld,usr,mysql,node2,local
From: https://www.cnblogs.com/lqy0917/p/17018527.html

相关文章