系统环境
标题 |
版本 |
备注 |
系统版本 |
CentOS-7-x86_64-Minimal-1908 |
- |
内核版本 |
3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux |
- |
MySQL |
v5.6.50 |
- |
MySQL 5.6.50 安装配置
基础环境
1.创建运行 mysql 用户 mysql:
1
| sudo useradd -s /sbin/nologin mysql
|
2.创建 mysql 数据存储目录和日志存储目录:
1
| sudo mkdir -p /data/mysql /var/log/mysql
|
安装 mysql
1.从 mysql 官方下载 mysql-5.6.50 二进制包到 /usr/local/src/ 目录下:
1
| sudo wget -O /usr/local/src/mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz
|
2.将下载好的二进制文件解压到下载目录:
1
| tar -zxf /usr/local/src/mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz -C /usr/local/src/
|
3.将解压出来的目录移动到 /usr/local/ 目录下并重命名为 mysql:
1
| sudo mv /usr/local/src/mysql-5.6.50-linux-glibc2.12-x86_64 /usr/local/mysql
|
4.进入到 /usr/local/mysql 目录:
5.将 mysql 安装目录,日志存放目录和数据存放目录的所属主和组都修改 mysql:
1
| sudo chown -R mysql:mysql /usr/local/mysql /var/log/mysql /data/mysql
|
6.执行 ./scripts/mysql_install_db --datadir=${datadir} --user=mysql --skip-name-resolve
命令初始化 mysql:
1
| sudo ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql --skip-name-resolve
|
配置 mysql
1.编辑 /etc/my.cnf 文件,写入以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| [mysqld]
bind-address = 0.0.0.0
port = 3306
pid-file = /data/mysql/mysql.pid
basedir = /usr/local/mysql/
datadir = /data/mysql
socket=/tmp/mysql.sock
character-set-server=utf8mb4
symbolic-link = 0
open_files_limit = 65535
log-error = /var/log/mysql/error.log
slow_query_log=on
long_query_time=2
slow_query_log_file = /var/log/mysql/slow_query.log
log-queries-not-using-indexes = 1
default_storage_engine=InnoDB
innodb_file_per_table = on
innodb_buffer_pool_size=4G
skip_name_resolve = on
lower_case_table_names = 1
query_cache_type=1 query_cache_limit = 2M query_cache_size = 64M
back_log = 500
max_connections = 1000
server_id=1 log_bin=mysql-bin
expire_logs_days = 7
max_binlog_size = 100m binlog_cache_size = 4m
max_binlog_cache_size = 512m
[mysqldump] quick
[mysql]
auto-rehash
default-character-set = utf8mb4 connect-timeout = 3
[client] default-character-set = utf8mb4 port = 3306 socket = /tmp/mysql.sock
[mysqld_safe]
open-files-limit = 8192
|
2.在 /etc/profile.d/
目录下创建 mysql.sh 文件,配置 mysql 系统环境:
1
| sudo echo 'PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
|
3.执行命令 source /etc/profile.d/mysql.sh
使其立即生效:
1
| source /etc/profile.d/mysql.sh
|
4.执行命令 mysql --version
看能否正常输入 Mysql 版本,如果能,则说明系统环境配置没问题:
1 2
| [root@localhost mysql]$ mysql --version mysql Ver 14.14 Distrib 5.6.50, for linux-glibc2.12 (x86_64) using EditLine wrapper
|
启动 mysql
1.在 /lib/systemd/system/ 目录下创建 mysql 启动脚本文件 mysql.service ,内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target
[Service] ExecStart=/usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql User=mysql Group=mysql TimeoutSec=300
[Install] WantedBy=multi-user.target
|
2.执行命令加载脚本:
1
| sudo systemctl daemon-reload
|
3.启动 mysql 服务并将其设置开机启动:
1
| sudo systemctl enable --now mysql.service
|
4.查看启动状态:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| [root@localhost mysql] ● mysql.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysql.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2023-09-25 03:27:10 EDT; 19min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 26940 (mysqld_safe) CGroup: /system.slice/mysql.service ├─26940 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql └─27409 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql --plugin-dir=/usr/local/mysql//lib/plugin --log-error=/var...
Sep 25 03:27:10 localhost.localdomain systemd[1]: Stopped MySQL Server. Sep 25 03:27:10 localhost.localdomain systemd[1]: Started MySQL Server. Sep 25 03:27:10 localhost.localdomain mysqld_safe[26940]: 230925 03:27:10 mysqld_safe Logging to '/var/log/mysql/error.log'. Sep 25 03:27:10 localhost.localdomain mysqld_safe[26940]: 230925 03:27:10 mysqld_safe Starting mysqld daemon with databases from /data/mysql
|