当前位置: 首页 > news >正文

MySQL8.0.33二进制包安装与部署

官方文档

https://downloads.mysql.com/archives/community/https://dev.mysql.com/doc/refman/8.1/en/binary-installation.html官方文档操作步骤
# Preconfiguration setup
$> groupadd mysql
$> useradd -r -g mysql -s /bin/false mysql
# Beginning of source-build specific instructions
$> tar zxvf mysql-VERSION.tar.gz
$> cd mysql-VERSION
# Postinstallation setup
$> cd /usr/local/mysql
$> mkdir mysql-files
$> chown mysql:mysql mysql-files
$> chmod 750 mysql-files
$> bin/mysqld --initialize --user=mysql
$> bin/mysql_ssl_rsa_setup
$> bin/mysqld_safe --user=mysql &
# Next command is optional
$> cp support-files/mysql.server /etc/init.d/mysql.server

环境准备

[root@node01 ~]# yum remove mariadb
[root@node01 ~]# yum install libaio-devel -y
[root@node01 ~]# rm -rf /etc/my.cnf

创建用户组和用户

[root@node01 ~]# id mysql
id: mysql: no such user[root@node01 ~]# groupadd -g 54321 mysql[root@node01 ~]# useradd -r -g mysql -s /bin/false -u 54321 mysql
[root@node01 ~]# id mysql
uid=54321(mysql) gid=54321(mysql) groups=54321(mysql)

下载、解压缩、创建软链接

1、wget下载mysql[root@node01 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.33-linux-glibc2.12-x86_64.tar2、解压缩[root@node01 ~]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar 
[root@node01 ~]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz -C /usr/local/cluster/3、创建软链接
[root@node01 ~]# ln -s /usr/local/cluster/mysql-8.0.33-linux-glibc2.12-x86_64/ /usr/local/mysql[root@node03 ~]# ll -h /usr/local/mysql/
total 292K
drwxr-xr-x  2 7161 31415 4.0K Mar 17 03:33 bin
drwxr-xr-x  2 7161 31415   38 Mar 17 03:33 docs
drwxr-xr-x  3 7161 31415  282 Mar 17 03:33 include
drwxr-xr-x  6 7161 31415  201 Mar 17 03:33 lib
-rw-r--r--  1 7161 31415 279K Mar 17 01:22 LICENSE
drwxr-xr-x  4 7161 31415   30 Mar 17 03:33 man
-rw-r--r--  1 7161 31415  666 Mar 17 01:22 README
drwxr-xr-x 28 7161 31415 4.0K Mar 17 03:33 share
drwxr-xr-x  2 7161 31415   77 Mar 17 03:33 support-files

创建数据目录

[root@node01 ~]# mkdir -p /data/mysql/3306/data
[root@node01 ~]# chown -R mysql:mysql /data/mysql/3306/data

参数配置

[root@node01 ~]# vim /etc/my.cnf[client]socket=/data/mysql/3306/data/mysql.sock
[mysql]
prompt="\\u@\\h [\\d]> "[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/3306/data
user=mysql
port=3306
pid-file=/data/mysql/3306/data/mysql.pid
socket=/data/mysql/3306/data/mysql.sock
log-error=/data/mysql/3306/data/mysql.err
log-timestamps=systemmysqlx_port=33060
mysqlx_socket=/data/mysql/3306/data/mysqlx.sock

初始化数据库

默认使用/etc/my.cnf参数文件
[root@node01 ~]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize看到日志输出显示临时密码说明初始化成功
[root@node01 ~]# more /data/mysql/3306/data/mysql.err | grep temporary
2023-07-28T14:32:43.094407+08:00 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: d&e:Vf=ss4D<

启动数据库


[root@node01 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 77851
[root@node01 ~]# 2023-07-28T06:33:14.981353Z mysqld_safe Logging to '/data/mysql/3306/data/mysql.err'.
2023-07-28T06:33:15.026927Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/3306/data[root@node01 ~]# ps -ef |grep mysql | grep -v grep
root      77851  69072  0 14:33 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
mysql     78013  77851 11 14:33 pts/1    00:00:03 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/3306/data/mysql.err --pid-file=/data/mysql/3306/data/mysql.pid --socket=/data/mysql/3306/data/mysql.sock --port=3306

配置环境变量

[root@node01 ~]# vim .bash_profile 
# .bash_profile# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrc
fi# User specific environment and startup programsPATH=$PATH:$HOME/binexport PATHexport JAVA_HOME=/usr/local/cluster/jdk
export PATH=$PATH:$JAVA_HOME/bin
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin[root@node01 ~]# source .bash_profile 

登录测试


登录成功
[root@node01 ~]# mysql -uroot -p -S /data/mysql/3306/data/mysql.sock
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.33Copyright (c) 2000, 2023, 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.

修改密码

[root@node01 ~]# mysql -uroot -p -S /data/mysql/3306/data/mysql.sock
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.33Copyright (c) 2000, 2023, 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.root@localhost [(none)]> select * from mysql.user\G
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
root@localhost [(none)]> alter user 'root'@'localhost' identified by 'oracle';
Query OK, 0 rows affected (0.00 sec)

使用配置文件启动


修改配置文件/usr/local/mysql/support-files/mysql.server通过查看配置文件/usr/local/mysql/support-files/mysql.server
basedir默认/usr/local/mysql
datadir默认/usr/local/mysql/data,修改为/data/mysql/3306/data
配置文件默认是/etc/my.cnf,不需要修改经过测试datadir不需要修改,因为配置文件默认是/etc/my.cnf,参数中指定了datadir的具体值[root@node01 ~]# vim /usr/local/mysql/support-files/mysql.serverbasedir=/usr/local/mysql
datadir=/data/mysql/3306/dataif test -z "$basedir"
thenbasedir=/usr/local/mysqlbindir=/usr/local/mysql/binif test -z "$datadir"thendatadir=/data/mysql/3306/datafisbindir=/usr/local/mysql/binlibexecdir=/usr/local/mysql/bin
elsebindir="$basedir/bin"if test -z "$datadir"thendatadir="$basedir/data"fisbindir="$basedir/sbin"libexecdir="$basedir/libexec"
fi使用配置文件/usr/local/mysql/support-files/mysql.server启动[root@node01 ~]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL................ SUCCESS![root@node01 ~]# /usr/local/mysql/support-files/mysql.server statusSUCCESS! MySQL running (102015)[root@node01 ~]# /usr/local/mysql/support-files/mysql.server stop
Shutting down MySQL... SUCCESS! 

配置systemctl服务

[root@node01 ~]# vim /usr/lib/systemd/system/mysqld.service[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://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
Type=notify
TimeoutSec=0# Execute pre and post scripts as root
PermissionsStartOnly=true# Start main service
#ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf $MYSQLD_OPTS# Use this to switch malloc implementation
#EnvironmentFile=-/etc/sysconfig/mysql# Sets open_files_limit
@LimitNOFILE = 5000Restart=on-failure
RestartPreventExitStatus=1PrivateTmp=false加载服务
[root@node01 ~]# systemctl daemon-reload
设置开机自启
[root@node01 ~]# systemctl enable mysqld.service[root@node01 ~]# systemctl start mysqld.service
[root@node01 ~]# systemctl status mysqld.service
[root@node01 ~]# systemctl stop mysqld.service[root@node01 ~]# systemctl disable mysqld.service
[root@node01 ~]# systemctl is-enabled mysqld.service[root@node01 ~]# systemctl status mysqld.service
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)Active: inactive (dead)Docs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlJul 27 19:20:44 node01 systemd[1]: [/usr/lib/systemd/system/mysqld.service:28] Unknown lvalue '@LimitNOFILE' in section 'Service'启动mysql
[root@node01 ~]# systemctl start mysqld.service
[root@node01 ~]# systemctl status mysqld.service
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)Active: active (running) since Thu 2023-07-27 19:24:00 CST; 2s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 113461 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=exited, status=0/SUCCESS)Main PID: 113725 (mysqld)Tasks: 39Memory: 291.3MCGroup: /system.slice/mysqld.service├─113474 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid└─113725 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/li...Jul 27 19:23:59 node01 systemd[1]: Starting MySQL Server...
Jul 27 19:24:00 node01 systemd[1]: mysqld.service: Supervising process 113725 which is not our child. We'll most likely no... exits.
Jul 27 19:24:00 node01 systemd[1]: Started MySQL Server.
Hint: Some lines were ellipsized, use -l to show in full.[root@node01 ~]# ps -ef |grep mysql
mysql    113474      1  0 19:23 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
mysql    113725 113474  4 19:23 ?        00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/data/mysql/mysql.err --pid-file=/data/mysql/mysql.pid --port=3306
root     113895 107141  0 19:24 pts/1    00:00:00 grep --color=auto mysql

配置文件最终版

[root@node01 ~]# more /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://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
Type=notify
TimeoutSec=0# Execute pre and post scripts as root
PermissionsStartOnly=true# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf $MYSQLD_OPTS# Use this to switch malloc implementation
#EnvironmentFile=-/etc/sysconfig/mysql# Sets open_files_limit
@LimitNOFILE = 5000Restart=on-failure
RestartPreventExitStatus=1PrivateTmp=false

http://www.lryc.cn/news/116808.html

相关文章:

  • RocketMQ发送消息失败:error CODE: 14 DESC: service not available now, maybe disk full
  • 1.Fay-UE5数字人工程导入(UE数字人系统教程)
  • Linux 终端操作命令(2)内部命令分类
  • 【数据结构与算法】十大经典排序算法-插入排序
  • 如何使用PHP Smarty进行条件判断和循环?
  • 使用svg生成图像
  • DNS、ARP
  • uniapp 微信小程序 echarts地图 点击显示类目
  • 速刷算法#Day-02
  • Java怎么手动将对象注入到springboot
  • twisted 18.7.0 requires PyHamcrest>=1.9.0 解决方案
  • 电脑关机程序
  • 构建之法 - 软工教学:每天都向前推进一点点
  • 基于Qlearning强化学习的路径规划算法matlab仿真
  • ASL国产CS5213 转VGA信号输出音频 替代AG6200安格芯片 HDMI to VGA(带音频)方案设计原理图
  • springboot启动忽略某些类
  • HCIA VLAN配置
  • 微信小程序--原生
  • Django快速上手
  • Android, 笔记+课表的app实现
  • Openlayers实战:多数据分散聚合
  • 9、Kubernetes核心技术 - Volume
  • HTML <small> 标签
  • 网页版Java(Spring/Spring Boot/Spring MVC)五子棋项目(四)对战模块
  • React实现关键字高亮
  • react-media如何使用
  • 多进程利用TCP进行信息群发功能
  • git 报错 protocol ‘https‘ is not supported解决
  • 启动RocketMQ报错
  • 【Spring Boot系列】-Spring Boot过滤器Filter