千家信息网

【MySQL】标准化安装教程

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,导读:本文主要介绍 CentOS 系统二进制安装 MySQL 5.7.23 版本的安装步骤,其他版本安装过程相似。1.前置准备卸载旧版MySQL查看rpm包rpm -qa|grep mysql 若有可
千家信息网最后更新 2025年01月20日【MySQL】标准化安装教程

导读:
本文主要介绍 CentOS 系统二进制安装 MySQL 5.7.23 版本的安装步骤,其他版本安装过程相似。

1.前置准备
  • 卸载旧版MySQL

    • 查看rpm包

    rpm -qa|grep mysql 若有可用rpm -e卸载

    • 查找mysql残留包,有则删除,没有则忽略

    find / -name mysql

  • 安装相关依赖

    yum -y install make gcc-c++ cmake bison-devel ncurses-devel numactl libaio

  • 创建用户和用户组

    groupadd mysql
    useradd -s /sbin/nologin -g mysql -M mysql

2.下载二进制安装包并解压
cd /usr/local/# wget下载或者本地下载后上传wget https://downloads.mysql.com/archives/get/file/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz# 解压安装包tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz# 解压后为了方便后面操作可把解压后文件名修改为mysqlmv mysql-5.7.23-linux-glibc2.12-x86_64 mysql# 更改文件夹所属chown -R mysql.mysql /usr/local/mysql/
3.创建mysql相关目录
mkdir -p /data/mysql/{data,logs,tmp}# 更改文件夹所属chown -R mysql.mysql /data/mysql/
4.创建mysql配置文件my.cnf
vi /etc/my.cnf# 简单模板如下:[client]port            = 3306socket          = /data/mysql/tmp/mysql.sock[mysqld]user = mysqlbasedir = /usr/local/mysql        datadir = /data/mysql/data  port = 3306               socket = /data/mysql/tmp/mysql.sockpid-file  = /data/mysql/tmp/mysqld.pidtmpdir = /data/mysql/tmp    skip_name_resolve = 1symbolic-links=0max_connections = 2000group_concat_max_len = 1024000sql_mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONlower_case_table_names = 1log_timestamps=SYSTEMcharacter-set-server = utf8interactive_timeout = 1800  wait_timeout = 1800max_allowed_packet = 32Mbinlog_cache_size = 4Msort_buffer_size = 2Mread_buffer_size = 4Mjoin_buffer_size = 4Mtmp_table_size = 96Mmax_heap_table_size = 96Mmax_length_for_sort_data = 8096#logsserver-id = 1003306log-error = /data/mysql/logs/error.logslow_query_log = 1slow_query_log_file = /data/mysql/logs/slow.loglong_query_time = 3log-bin = /data/mysql/logs/binlogbinlog_format = rowexpire_logs_days = 15log_bin_trust_function_creators = 1relay-log = /data/mysql/logs/relay-binrelay-log-recovery = 1  relay_log_purge = 1  #innodb  innodb_file_per_table = 1innodb_log_buffer_size = 16Minnodb_log_file_size = 256Minnodb_log_files_in_group = 2innodb_io_capacity = 2000innodb_io_capacity_max = 4000innodb_flush_neighbors = 0innodb_flush_method = O_DIRECTinnodb_autoinc_lock_mode = 2innodb_read_io_threads = 8innodb_write_io_threads = 8innodb_buffer_pool_size = 2G
5.配置mysql.server
cd /usr/local/mysql/support-filescp mysql.server /etc/init.d/mysqlvi /etc/init.d/mysql# 修改目录位置basedir=/usr/local/mysqldatadir=/data/mysql/data# 注册开机启动服务chkconfig --add mysqlchkconfig --list
6.添加环境变量
echo "PATH=$PATH:/usr/local/mysql/bin  " >> /etc/profile  source /etc/profile
7.初始化mysql
/usr/local/mysql/bin/mysqld  --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data# 临时密码保存在errlog中 # 获取临时密码more /data/mysql/logs/error.log |grep password
8.启动mysql服务 并修改密码
# 启动mysql服务service mysql start# 使用初始密码登录mysql服务 并修改密码mysql -uroot -palter user 'root'@'localhost' identified by 'root';flush privileges;

0