0
点赞
收藏
分享

微信扫一扫

rhel 7.3安装mysql 8.0.27

ITWYY 2023-05-26 阅读 66

文档课题:rhel 7.3安装mysql 8.0.27.
系统:rhel 7.3 64位
数据库:mysql 8.0.27
安装包:mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
1、安装前检查
1.1、系统版本
[root@leo-mysql-master ~]# cat /etc/*release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.3 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="7.3"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.3 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.3:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.3
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.3"
Red Hat Enterprise Linux Server release 7.3 (Maipo)
Red Hat Enterprise Linux Server release 7.3 (Maipo)
1.2、确认安装情况
--检查是否安装mysql.
[root@leo-mysql-master ~]# rpm -qa | grep mysql
--检查是否存在mysql用户.
[root@leo-mysql-master ~]# id mysql
id: mysql: no such user 
1.3、检查库文件
--检查库文件是否安装.
[root@leo-mysql-master ~]# rpm -qa | grep libaio
libaio-0.3.109-13.el7.x86_64
说明:若未安装库文件,则需要安装.
[root@leo-mysql-master ~]# yum -y install libaio-devel.x86_64
[root@leo-mysql-master ~]# yum -y install numactl
2、开始安装
2.1、建组和用户
--新建mysql组和mysql用户.
[root@leo-mysql-master ~]# groupadd mysql
[root@leo-mysql-master ~]# useradd -r -g mysql mysql
2.2、软件包处理
--上传mysql软件包.
sftp> lcd F:\installmedium\mysql
sftp> put mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
--解压安装包.
[root@leo-mysql-master ~]# tar -xvf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
--重命名.
[root@leo-mysql-master ~]# mkdir -p /opt
[root@leo-mysql-master ~]# mv mysql-8.0.27-linux-glibc2.12-x86_64 /opt/mysql
[root@leo-mysql-master opt]# chown -R root:root /opt/mysql
--建数据存储目录.
[root@leo-mysql-master mysql]# mkdir -p /opt/mysql/data
[root@leo-mysql-master mysql]# chown mysql:mysql /opt/mysql/data
2.3、初始化数据库
[root@leo-mysql-master ~]# ll /etc/ | grep my.cnf
-rw-r--r--.  1 root root      570 Sep 21  2016 my.cnf
drwxr-xr-x.  2 root root       31 May 26 15:35 my.cnf.d
[root@leo-mysql-master ~]# mv /etc/my.cnf /etc/my.cnf.bak
[root@leo-mysql-master ~]# ll /etc/ | grep my.cnf
-rw-r--r--.  1 root root      570 Sep 21  2016 my.cnf.bak
drwxr-xr-x.  2 root root       31 May 26 15:35 my.cnf.d
开始初始化
[root@leo-mysql-master ~]# /opt/mysql/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
2023-05-26T08:27:50.200958Z 0 [System] [MY-013169] [Server] /opt/mysql/bin/mysqld (mysqld 8.0.27) initializing of server in progress as process 47423
2023-05-26T08:27:50.208997Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-05-26T08:27:50.773990Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-05-26T08:27:51.731006Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2023-05-26T08:27:51.731046Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2023-05-26T08:27:51.863805Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: )YoTudkto5sK

说明:注意复制初始化密码)YoTudkto5sK
2.4、修改配置文件
--进入mysql安装目录support-files,创建mysql-default.cnf文件并添加权限.
[root@leo-mysql-master ~ ]# cd /opt/mysql/support-files
[root@leo-mysql-master support-files]# touch mysql-default.cnf
[root@leo-mysql-master support-files]# chmod 777 mysql-default.cnf
[root@leo-mysql-master support-files]# ll
total 20
-rwxrwxrwx. 1 root root     0 May 26 16:30 mysql-default.cnf
-rwxr-xr-x. 1 root root  1061 Sep 28  2021 mysqld_multi.server
-rw-r--r--. 1 root root  2027 Sep 28  2021 mysql-log-rotate
-rwxr-xr-x. 1 root root 10576 Sep 28  2021 mysql.server
--将其复制到/etc下,并改名为my.cnf.
[root@leo-mysql-master support-files]# cp -a mysql-default.cnf /etc/my.cnf
[root@leo-mysql-master ~]# vi /etc/my.cnf
添加如下:
[mysqld]
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
log-error=/opt/mysql/data/error.log
pid-file=/opt/mysql/data/mysql.pid
port=3306
max_allowed_packet=32M
--修改配置文件权限.
[root@leo-mysql-master ~]# chmod 644 /etc/my.cnf
2.5、关闭防火墙
[root@leo-mysql-master ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2023-05-26 15:43:25 CST; 1h 10min ago
     Docs: man:firewalld(1)
 Main PID: 878 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─878 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

May 26 15:43:25 leo-mysql-master systemd[1]: Starting firewalld - dynamic firewall daemon...
May 26 15:43:25 leo-mysql-master systemd[1]: Started firewalld - dynamic firewall daemon.
[root@leo-mysql-master ~]# systemctl stop firewalld
[root@leo-mysql-master ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
3、设置开启自启
3.1、mysql服务处理
--复制mysql服务文件到/etc/init.d目录,重命名为mysql.
[root@leo-mysql-master ~]# cp -a /opt/mysql/support-files/mysql.server /etc/init.d/mysql
[root@leo-mysql-master ~]# ll /etc/init.d/mysql
-rwxr-xr-x. 1 root root 10576 Sep 28  2021 /etc/init.d/mysql
--添加可执行权限.
[root@leo-mysql-master ~]# chmod +x /etc/init.d/mysql
--注册服务.
[root@leo-mysql-master ~]# chkconfig --add mysql
--检测.
[root@leo-mysql-master ~]# chkconfig --list mysql

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
3.2、环境变量处理
/etc/ld.so.conf要配置路径,否则报错
[root@leo-mysql-master ~]# vi /etc/ld.so.conf
--添加mysql的lib文件
/opt/mysql/lib

--配置环境变量.
[root@leo-mysql-master ~]# vi /etc/profile
添加如下:
export PATH=$PATH:/opt/mysql/bin:/opt/mysql/lib

--重新加载使环境变量生效.
[root@leo-mysql-master ~]# source /etc/profile

4、修改默认密码
--启动服务.
[root@leo-mysql-master ~]# service mysql start
Starting MySQL.Logging to '/opt/mysql/data/error.log'.
 SUCCESS!
[root@leo-mysql-master ~]# ps -ef|grep mysql
avahi       848      1  0 15:43 ?        00:00:00 avahi-daemon: running [leo-mysql-master.local]
root      47855      1  0 16:50 pts/2    00:00:00 /bin/sh /opt/mysql/bin/mysqld_safe --datadir=/opt/mysql/data --pid-file=/opt/mysql/data/mysql.pid
mysql     48032  47855  5 16:50 pts/2    00:00:00 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=/opt/mysql/data/error.log --pid-file=/opt/mysql/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root      48089  14757  0 16:50 pts/2    00:00:00 grep --color=auto mysql
[root@leo-mysql-master ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27

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> alter user 'root'@'localhost' identified by 'mysql_4U';
Query OK, 0 rows affected (0.01 sec)

参考文档:https://blog.csdn.net/weixin_45648789/article/details/129033802?spm=1001.2014.3001.5502

举报

相关推荐

0 条评论