下载二进制格式的软件包
mysql包位置:(https://downloads.mysql.com/archives/community/)
#下载地址mysql 选择5.7.39版本 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 ~]#
创建用户和组
[root@node2 ~]# useradd -r -M -s /sbin/nologin -u 306 mysql
[root@node2 ~]# id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)
[root@node2 ~]#
解压软件至/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]# ll
total 0
...
drwxr-xr-x. 2 root root 6 Jun 22 2021 lib
drwxr-xr-x. 3 root root 17 Dec 13 15:19 lib64
drwxr-xr-x. 2 root root 6 Jun 22 2021 libexec
drwxr-xr-x. 9 root root 129 Dec 29 18:14 mysql-5.7.39-linux-glibc2.12-x86_64
...
#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 18:16 mysql -> /usr/local/mysql-5.7.39-linux-glibc2.12-x86_64
drwxr-xr-x. 9 root root 129 Dec 29 18:14 mysql-5.7.39-linux-glibc2.12-x86_64
...
修改目录/usr/local/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
...
设置环境变量
echo写入环境变量到/etc/profile.d/mysqld.sh
[root@node2 local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysqld.sh
[root@node2 local]# source /etc/profile.d/mysqld.sh
[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]# vim /etc/ld.so.conf.d/mysqld.conf
/usr/local/mysql/lib
[root@node2 local]# ldconfig
设置man文档
修改/etc/man_db.conf
#添加一行/usr/local/mysql/man
[root@node2 local]# vim /etc/man_db.conf
...
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/mysql/man
...
建立数据存放目录
[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]#
初始化数据库
[root@node2 local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2022-12-29T10:32:51.361985Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-12-29T10:32:51.797907Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-12-29T10:32:51.858134Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-12-29T10:32:51.922226Z 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: 25d0036c-8764-11ed-998a-000c2987473b.
2022-12-29T10:32:51.923982Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-12-29T10:32:52.120715Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-12-29T10:32:52.120742Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-12-29T10:32:52.121096Z 0 [Warning] CA certificate ca.pem is self signed.
2022-12-29T10:32:52.188890Z 1 [Note] A temporary password is generated for root@localhost: o&<k17Fa%nk.
#请注意,这个命令的最后会生成一个临时密码,临时密码只能使用一次
[root@node2 local]#
生成配置文件
#如果有my.cnf文件 将其备份一份 再清空去修改
#修改配置文件my.cnf
[root@node2 etc]# vim /etc/my.cnf
[mysqld] #指mysqld程序
basedir = /usr/local/mysql #basedir指安装目录
datadir = /opt/data #datadir数据存放位置
socket = /tmp/mysql.sock #套接字文件位置
port = 3306 #port端口号
pid-file = /opt/data/mysql.pid#pid文件存放位置
user = mysql #user用户
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
配置服务启动脚本
#在安装目录下的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
...
启动mysql并设置开机自启
[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]#
[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
ExecStart=/usr/local/mysql/support-files/mysql.server start #设置启动start
ExecStop=/usr/local/mysql/support-files/mysql.server stop #设置停止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.
[root@node2 ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disab>
Active: active (running) since Thu 2022-12-29 19:04:23 CST; 9s ago
Process: 999 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=exited,>
Main PID: 1027 (mysqld_safe)
Tasks: 28 (limit: 4723)
Memory: 209.7M
CGroup: /system.slice/mysqld.service
├─1027 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-fil>
└─1246 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/>
Dec 29 19:04:19 node2 systemd[1]: Starting mysqld server daemon...
Dec 29 19:04:23 node2 mysql.server[999]: Starting MySQL.... SUCCESS!
Dec 29 19:04:23 node2 systemd[1]: Started mysqld server daemon.
[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 ~]#
使用临时密码登录并修改密码
[root@node2 ~]# yum provides libncurses.so.5 #安装libncurses.so.5标签:二进制,root,部署,mysqld,usr,mysql,node2,local From: https://www.cnblogs.com/msl1105/p/17013360.html
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 06:45:35 PM CST.
Dependencies resolved.
============================================================================================================
...
Complete!
[root@node2 ~]# mysql -uroot -p'o&<k17Fa%nk.' #使用临时密码登录
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> use mysql;
Database changed
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.00 sec)
mysql> set password for 'root'@'localhost' =password('mashuangle123!'); #修改密码
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@node2 ~]# mysql -uroot -pmashuang123le!
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>