//安装依赖包
[root@slave ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:18:58 前,执行于 2021年10月26日 星期二 00时14分11秒。
软件包 openssl-devel-1:1.1.1c-15.el8.x86_64 已安装。
软件包 openssl-1:1.1.1c-15.el8.x86_64 已安装。
//创建用户和组
[root@slave ~]# useradd -r -M -s /sbin/nologin mysql
//下载二进制格式的mysql软件包
[root@slave ~]# cd /usr/src/
[root@slave src]# ls
debug kernels nginx-1.20.1 nginx-1.20.1.tar.gz
[root@slave src]# ls
debug kernels mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz nginx-1.20.1 nginx-1.20.1.tar.gz
[root@slave src]# tar xf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@slave src]# ls /usr/local/
bin games lib libexec nginx share
etc include lib64 mysql-5.7.35-linux-glibc2.12-x86_64 sbin src
[root@slave src]# cd /usr/local/
[root@slave local]# mv mysql-5.7.35-linux-glibc2.12-x86_64 mysql
[root@slave local]# ls
bin etc games include lib lib64 libexec mysql nginx sbin share src
[root@slave local]#
//修改目录/usr/local/mysql的属主属组
[root@slave local]# chown -R mysql.mysql mysql
//添加环境变量
[root@slave local]# cd
[root@slave ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@slave ~]# source /etc/profile.d/mysql.sh
[root@slave ~]# ls /usr/local/mysql/
bin include LICENSE README support-files
docs lib man share
[root@slave ~]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@slave ~]#
[root@slave ~]# vim /etc/man_db.conf
[root@slave ~]# cat /etc/man_db.conf
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/apache/man
MANDATORY_MANPATH /usr/local/mysql/man //添加这一行内容
[root@slave ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@slave ~]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/msyql/lib
[root@slave ~]# ldconfig
[root@slave ~]#
//建立数据存放目录
[root@slave ~]# mkdir /opt/data
[root@slave ~]# chown -R mysql.mysql /opt/data
[root@slave ~]# bash
//初始化数据库
[root@slave ~]# chown -R mysql.mysql /opt/data
[root@slave ~]# mysqld --initialize-insecure --user mysql --datadir /opt/data
2021-10-26T04:42:05.716459Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-10-26T04:42:05.856574Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-10-26T04:42:05.890416Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-10-26T04:42:05.945415Z 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: 12380e70-3617-11ec-9a5a-000c292ea5d7.
2021-10-26T04:42:05.946349Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-10-26T04:42:06.840383Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-10-26T04:42:06.840411Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-10-26T04:42:06.840771Z 0 [Warning] CA certificate ca.pem is self signed.
2021-10-26T04:42:06.948775Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
//生成配置文件
[root@slave ~]# cat > /etc/my.cnf <<EOF
> [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
> EOF
[root@slave ~]# 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
[root@slave ~]#
[root@slave ~]# cp /usr/lib/systemd/system/httpd.service /usr/lib/systemd/system/mysqld.service
[root@master ~]# vim /usr/lib/systemd/system/mysqld.service
[root@master ~]# cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=Mysql server daemon
After=network.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@slave ~]#
[root@slave ~]# vim /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/opt/data //修改这两行内容
//开机自启
[root@slave ~]# systemctl daemon-reload
[root@slave ~]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@slave ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
//修改密码
[root@slave ~]# yum -y install ncurses-compat-libs
[root@slave ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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> set password = password('xiongke');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@slave ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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>