一、准备环境
1.1 安装包
可以直接在这个页面下载,也可以到官网下载mysql.com
1.2 安装需要的依赖
curl -O http://kode.huhuhahei.cn/index.php?user/publicLink\&fid=2493D9TIfgnJtc4FvMKOj1EJ5_skR0B695C3of0ZsbNu2mp0WCIPHYOfdZXyzQ6aBAUQbYWtb6pVAhQBB1jzdpFW5M2TxJZtyLLchhvJUUSFGXLuXI5xaocqSsBdj0LsGhA\&file_name=/mysql-5.6.40.tar.gz
yum install -y ncurses-devel libaio-devel cmake gcc-c++ autoconf lrzsz
1.3 解压tar包
tar xf mysql-5.6.40.tar.gz
cd mysql-5.6.40
二、编译配置
2.1 编译
#创建安装目录
mkdir /application
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.40 -DMYSQL_DATADIR=/application/mysql-5.6.40/data -DMYSQL_UNIX_ADDR=/application/mysql-5.6.40/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_ZLIB=bundled-DWITH_SSL=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLE_DOWNLOADS=1 -DWITH_DEBUG=0
make && make install
三、配置优化
3.1 文件路径调优
#创建用户
useradd mysql -s /sbin/nologin -M
#创建socket文件目录
mkdir -p /application/mysql-5.6.40/tmp
#配置软连接
ln -s /application/mysql-5.6.40/ /application/mysql
#复制配置文件
cp support-files/my-default.cnf /etc/my.cnf
#配置启动命令
cp support-files/mysql.server /etc/init.d/mysqld
#修改属主属组
chown -R mysql:mysql /application/mysql
chown -R mysql:mysql /application/mysql-5.6.40/
3.2 初始化数据库
cd scripts/
./mysql_install_db --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data
3.3 配置环境变量
cat /etc/profile.d/mysql.sh
export PATH="/application/mysql/bin:$PATH"
source /etc/profile.d/mysql.sh
#启动mysql
/etc/init.d/mysqld start
#可以登陆了
mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.40 Source distribution
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
3.4 配置systemctl控制
cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
systemctl start mysqld
systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2021-10-28 14:41:09 CST; 8s ago
Docs: man:mysqld(8)
https://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 12236 (mysqld)
Tasks: 21
CGroup: /system.slice/mysqld.service
└─12236 /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
Oct 28 14:41:09 192-168-0-49 mysqld[12236]: 2021-10-28 14:41:09 12236 [Note] I....
Oct 28 14:41:09 192-168-0-49 mysqld[12236]: 2021-10-28 14:41:09 12236 [Note] I...t
Oct 28 14:41:09 192-168-0-49 mysqld[12236]: 2021-10-28 14:41:09 12236 [Note] I...7
Oct 28 14:41:09 192-168-0-49 mysqld[12236]: 2021-10-28 14:41:09 12236 [Note] S...6
Oct 28 14:41:09 192-168-0-49 mysqld[12236]: 2021-10-28 14:41:09 12236 [Note] I....
Oct 28 14:41:09 192-168-0-49 mysqld[12236]: 2021-10-28 14:41:09 12236 [Note] ...;
Oct 28 14:41:09 192-168-0-49 mysqld[12236]: 2021-10-28 14:41:09 12236 [Note] S....
Oct 28 14:41:09 192-168-0-49 mysqld[12236]: 2021-10-28 14:41:09 12236 [Note] E...s
Oct 28 14:41:09 192-168-0-49 mysqld[12236]: 2021-10-28 14:41:09 12236 [Note] /....
Oct 28 14:41:09 192-168-0-49 mysqld[12236]: Version: '5.6.40' socket: '/appli...n
Hint: Some lines were ellipsized, use -l to show in full.