MySQL8.4一主一从环境搭建

MySQL8.4一主一从环境搭建

一、MySQL数据库服务环境搭建

1.1、下载及上传mysql二进制安装包

下载地址

MySQL :: Download MySQL Community Server

上传mysql-8.4.0-linux-glibc2.17-x86_64.tar.xz到soft目录
ls -lsa /soft

1.2、增加MySQL用户组及用户


groupadd mysql
useradd -r -s /bin/false -g mysql mysql

mkdir -p /mysql/data/3306/data
mkdir -p /mysql/backup/backup-db

chown -R mysql:mysql /mysql

1.3、编辑配置文件my.cnf

vi /mysql/data/3306/my.cnf


[mysqld]
server-id=573306
port=3306
basedir=/mysql/app/mysql
datadir=/mysql/data/3306/data
log-error=/mysql/log/3306/superdb-error.log
socket=/mysql/data/3306/mysql.sock
pid-file=/mysql/data/3306/mysql.pid
character-set-server=utf8mb4
lower_case_table_names=1
innodb_log_file_size=1G
default-storage-engine=INNODB
mysql_native_password=on
secure_file_priv=''


[mysql]
prompt=(\\u@\\h)[\\d]>\\_

[client]
port=3306
default-character-set=utf8mb4

1.4、解压


cd /soft
ls
xz -d mysql-8.4.0-linux-glibc2.17-x86_64.tar.xz
tar xvf mysql-8.4.0-linux-glibc2.17-x86_64.tar
mv mysql-8.4.0-linux-glibc2.17-x86_64 /mysql/app/mysql

1.5、mysql初始化
 

/mysql/app/mysql/bin/mysqld  --defaults-file=/mysql/data/3306/my.cnf  --initialize --user=mysql --basedir=/mysql/app/mysql --datadir=/mysql/data/3306/data

1.6、安全模式启动mysql
 

/mysql/app/mysql/bin/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf  &

1.7、设置软连接sock软连接

ln -sf /mysql/data/3306/mysql.sock /tmp/mysql.sock

1.8、编辑环境变量mysql home目录及登陆提示

vi ~/.bash_profile

PATH=$PATH:/mysql/app/mysql/bin:$HOME/bin
export MYSQL_PS1="(\u@\h:\p)[\d]>"

source ~/.bash_profile


tail -fn300 /mysql/log/3306/superdb-error.log


1.9、登陆mysql设置密码

defaultmysqlpwd=`grep 'A temporary password' /mysql/log/3306/superdb-error.log |awk -F "root@localhost: " '{ print $2}' |tail -n1`
mysql -uroot -p"${defaultmysqlpwd}" --connect-expired-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@2024';
EOF
sleep 1

mysql -uroot -p

create user 'root'@'%' identified  by 'Root@2024';
grant all privileges on *.* to 'root'@'%';
flush privileges;
exit

1.10、设置service mysqld 服务


mv /mysql/app/mysql/support-files/mysql.server /mysql/app/mysql/support-files/mysql.server.bak

vi /mysql/app/mysql/support-files/mysql.server

#!/bin/sh
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind

# MySQL daemon start/stop script.

# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
# When this is done the mysql server will be started when the machine is
# started and shut down when the systems goes down.

# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.

# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MySQL
# Description: MySQL is a very fast and reliable SQL database engine.
### END INIT INFO
 
# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
#   [mysqld]
#   basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
#   and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
#   below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/mysql/app/mysql
datadir=/mysql/data/3306/data

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start. 
# Value here is overriden by value in my.cnf. 
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"

# The following variables are only set for letting mysql.server find things.

# Set some defaults
mysqld_pid_file_path&
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值