mysql-8.0安装
【摘要】 mysql8.0安装
软件下载:https://downloads.mysql.com/archives/community/
wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
一、环境准备
1、修改主机名
hostnamectl set-hostname master
2、安装依赖
yum install libaio numactl -y
3、创建用户以及用户组
groupadd mysql
useradd -m -r -g mysql mysql
4、配置 limit
修改limit参数,调整文件句柄和进程数
vi /etc/security/limits.conf 文件,在文件末尾写上
mysql soft nproc 65536
mysql hard nproc 65536
mysql soft nofile 65536
mysql hard nofile 65536
vi /etc/security/limits.d/90-nproc.conf 把参数调整为
* soft nproc 65536
root soft nproc unlimited
* soft nofile 65536
root soft nofile unlimited
5、调整system参数
vim /etc/systemd/system.conf
#内核参数优化
#少用交换分区
vm.swappiness <= 5
vm.dirty_ratio <= 20
vm.dirty_background_ratio <= 10
net.ipv4.tcp_max_syn_backlog = 819200
net.core.netdev_max_backlog = 400000
net.core.somaxconn = 4096
#解决time_wait过高导致数据库连接不上
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
5、在 hosts 文件加上本机解析
host_ip=$(ifconfig | grep inet | grep cast | awk '{print $2}' | awk -F: '{print $NF}' | head -1)
echo "$host_ip `hostname`" >> /etc/hosts
6、关闭 iptable
关闭防火墙,如果不允许关闭可以开放对应端口
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
7、关闭 selinux
#查看 selinux 状态
getenforce
#临时关闭
setenforce 0
#永久关闭
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
二、安装
安装数据目录为 /data/mysql_db/,日志目录为 /data/mysql_log/,启动用户为 mysql,这个可以随自己环境设置,但要替换脚本所有目录
1、解压文件
解压安装包,放到 /user/local/ 目录下
tar -xvzf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql8
mysql配置环境变量
export MYSQL_HOME=/usr/local/mysql8
export PATH=${MYSQL_HOME}/bin:$PATH
PS1=`uname -n`":"'$USER'":"'$PWD'":>"; export PS1
2、创建数据和日志目录
mkdir -p /data/mysql_db
mkdir -p /data/mysql_log
3、生成配置文件
vi /etc/my.cnf
安装参数结合自己实际情况配置
[mysqld]
basedir=/usr/local/mysql8
datadir=/data/mysql_db
socket=/data/mysql_db/mysql.sock
character-set-server=utf8
port=3306
skip-external-locking = 1
skip-name-resolve = 1
port = 3306
server_id = 8201
lower_case_table_names = 1
#innodb_file_format=Barracuda
max_connections=3000
log_bin_trust_function_creators=1
default-storage-engine = InnoDB
character-set-server = utf8mb4
default_password_lifetime=0
#### log ####
binlog_cache_size = 16M
log_bin = /data/mysql_log/mysql-bin
log_bin_index = /data/mysql_log/mysql-bin.index
binlog_format = row
expire_logs_days = 5
relay_log_recovery=ON
relay_log=/data/mysql_log/mysql-relay-bin
relay_log_index=/data/mysql_log/mysql-relay-bin.index
log_error = /data/mysql_log/mysql-error.log
log_queries_not_using_indexes = 1
slow_query_log = 1
long_query_time = 1
#slow_query_log_file = /data/mysql_log/mysql-slow.log
#### innodb ####
innodb_buffer_pool_size = 4G
innodb_buffer_pool_instances = 8
innodb_log_group_home_dir = /data/mysql_log/
innodb_undo_directory = /data/mysql_log/
innodb_flush_neighbors = 1
innodb_log_file_size = 1G
innodb_file_per_table = on
[mysql]
prompt="\u@\h \R:\m:\s [\d]> "
4、初始化目录
mysql8.0需要初始化是加上不区分大小写
/usr/local/mysql8/bin/mysqld --initialize-insecure --lower-case-table-names=1 --basedir=/usr/local/mysql8 --datadir=/data/mysql_db --user=mysql --initialize
## --initialize生成随机密码,--initialize-insecure不生成密码##
5、生成启动文件
cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysqld
把
basedir=
datadir=
改为, 手动指定配置文件和数据目录
basedir=/usr/local/mysql8
datadir=/data/mysql_db
把数据目录的所有者改为 mysql
chown mysql.mysql /etc/init.d/mysqld
chown mysql.mysql -R /data/mysql*
6、启动实例
以 mysql 用户来启动
su - mysql
/etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
进入 mysql 客户端
mysql -S /data/mysql_db/mysql.sock
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)