详细步骤助你轻松部署
在当今的信息技术领域,数据库是存储和管理数据的核心组件。MySQL,作为最受欢迎的开源关系型数据库管理系统之一,以其高性能、可靠性和易用性而闻名。本文将为您提供详细的MySQL 8.0.28版本的安装步骤,帮助您快速部署并开始使用这一强大的数据库系统。
服务
器初始化安装
1、首先,我们需要准备服务器环境。建议安装以下依赖项以确保MySQL能够顺利运行:
yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio perl-Data-Dumper net-tools libaio-devel perl zlib*
复制
同时,为了便于运维监控,推荐安装以下工具:
yum -y install unzip* gzip* zip* tar* lrzsz* twm* xterm* pixman* pixman-devel* fio* ntp* telnet* bc* dos2unix* net-tools* iperf* iftop* iotop* psmisc* lsof* nethogs* htop*
复制
2、接下来,我们需要修改系统内核参数以优化MySQL的性能:
echo "net.ipv4.tcp_syncookies = 1" >> etc/sysctl.conf
echo "fs.file-max = 1000000" >> etc/sysctl.conf
echo "vm.swappiness = 0" >> etc/sysctl.conf
echo "net.core.somaxconn = 26214" >> etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 30" >> etc/sysctl.conf
echo "net.ipv4.tcp_keepalive_time = 120" >> etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse = 1" >> etc/sysctl.conf
echo "net.ipv4.tcp_timestamps = 1" >> etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle = 0" >> etc/sysctl.conf
echo "net.ipv4.tcp_max_tw_buckets = 20000" >> etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog = 65535" >> etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 10240 65000" >> etc/sysctl.conf
复制
修改之后执行`sysctl -p`使配置生效。
3、系统配置与安全设置
在安装MySQL之前,还需要对系统的一些限制参数进行调整:
echo "www-data soft noproc 65535>> /etc/security/limits.conf
echo "www-data hard noproc 65535>> /etc/security/limits.conf
echo "www-data soft nofile 65535>> /etc/security/limits.conf
echo "www-data hard nofile 65535>> /etc/security/limits.conf
echo "www-data soft stack 65535>> /etc/security/limits.conf
echo "www-data hard stack 65535>> /etc/security/limits.conf
复制
4、关闭Selinux和防火墙
此外,为了确保系统的安全性和兼容性,建议关闭Selinux和防火墙:
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
复制
#首先移除服务器自带的mariadb
yum -y remove mariadb*
mkdir -p /data/mysql/data
groupadd mysql
useradd -g mysql -r -s /sbin/nologin -M -d /usr/local/mysql mysql
复制
/etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
复制
解压软件
tar -xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
mkdir /data/mysql
mv mysql-8.0.28-linux-glibc2.12-x86_64 /data/mysql/mysql-8.0.28
ln -s /data/mysql/mysql-8.0.28 /usr/local/mysql
chown -R mysql:mysql /data/mysql /usr/local/mysql
复制
[mysqld]
bind-address=0.0.0.0
port= 3306
user= mysql
basedir=/data/mysql/mysql-8.0.28
datadir=/data/mysql/mysql-8.0.28/data
socket=/data/mysql/mysql-8.0.28/data/mysql.sock
#tmpdir=/data/mysql/mysql-8.0.28/data/mysql-tmp/
log-error=/data/mysql/mysql-8.0.28/data/mysql3306err.log
pid-file=/data/mysql/mysql-8.0.28/data/mysql3306.pid
authentication_policy= mysql_native_password # MySQL 5.7 无此参数
### Server Config ###
server-id= 1
autocommit = 1
character-set-server=utf8
collation-server = utf8_general_ci
init_connect='SET NAMES utf8'
skip_name_resolve = 1
open_files_limit = 65535
max_connections = 30000
max_connect_errors = 100
interactive_timeout = 18800
wait_timeout = 18800
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
table_open_cache = 4000
max_allowed_packet = 16M
join_buffer_size = 128M
tmp_table_size = 128M
max_heap_table_size = 128M
read_buffer_size = 16M
read_rnd_buffer_size = 32M
sort_buffer_size = 32M
lower_case_table_names= 1
explicit_defaults_for_timestamp=true
### slow query config ###
slow_query_log = on
long_query_time = 600
slow_query_log_file =/data/mysql/mysql-8.0.28/data/mysql-log/slowquery.log
### binlog config ###
#gtid_mode = on
#enforce_gtid_consistency = on
innodb-file-per-table = 1
#sync_binlog = 1
log-bin=/data/mysql/mysql-8.0.28/data/mysql-bin
binlog_format = row
binlog_expire_logs_seconds = 172800
max_binlog_size = 1G
binlog_ignore_db = mysql
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
### innodb config ###
innodb_log_files_in_group = 5
#innodb_log_group_home_dir= /data/mysql/mysql-8.0.28/data/redo-log/
#innodb_undo_directory = /data/mysql/mysql-8.0.28/data/undo-log/
#innodb_page_size = 16K
# 0.8*Physical Memory for the dedicated MySQL Server,be equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances
innodb_buffer_pool_size = 13455346892
innodb_buffer_pool_instances = 20
innodb_log_file_size = 1G
innodb_log_buffer_size = 100M
#innodb_thread_concurrency = 64
[mysql]
default-character-set=utf8
socket=/data/mysql/mysql-8.0.28/data/mysql.sock
[client]
default-character-set=utf8
socket=/data/mysql/mysql-8.0.28/data/mysql.sock
[mysqld_safe]
socket=/data/mysql/mysql-8.0.28/data/mysql.sock
log-error=/data/mysql/mysql-8.0.28/data/mysql3306err.log
pid-file=/data/mysql/mysql-8.0.28/data/mysql3306.pid
复制
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/data/mysql/mysql-8.0.28 --datadir=/data/mysql/mysql-8.0.28/data --initialize-insecure
复制
10、配置开机自启及启动数据库
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 2345 mysql on
#启动数据库
service mysql start
复制
11、创建和修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123tst';
create user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123tst';
#授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
flush privileges;
#PS:本次为演示操作,所以设置密码比较简单,生产环境建议复杂度设置更高一些。
复制
至此,MySQL 8.0.28已成功安装并配置完成。您可以开始使用这个强大的数据库系统来管理您的数据了。
文章转载自山佳数峰寻道,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
【专家有话说第五期】在不同年龄段,DBA应该怎样规划自己的职业发展?
墨天轮编辑部
1332次阅读
2025-03-13 11:40:53
MySQL8.0统计信息总结
闫建(Rock Yan)
502次阅读
2025-03-17 16:04:03
2月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
472次阅读
2025-03-13 14:38:19
SQL优化 - explain查看SQL执行计划(一)
金同学
400次阅读
2025-03-13 16:04:22
MySQL突然崩溃?教你用gdb解剖core文件,快速锁定“元凶”!
szrsu
379次阅读
2025-03-13 00:29:43
SQLE 4.0 正式版发布,新增 SQL 重写、SQL 性能追踪、语法知识图谱等功能
爱可生开源社区
368次阅读
2025-03-07 10:30:00
MySQL生产实战优化(利用Index skip scan优化性能提升257倍)
chengang
333次阅读
2025-03-17 10:36:40
MySQL数据库当前和历史事务分析
听见风的声音
311次阅读
2025-04-01 08:47:17
MySQL 生产实践-Update 二级索引导致的性能问题排查
chengang
268次阅读
2025-03-28 16:28:31
墨天轮个人数说知识点合集
JiekeXu
245次阅读
2025-04-01 15:56:03