mysql-5.7.* 编译安装

系统 CentOS 7.9 

userdel -r mysql
yum -y remove mariadb mariadb-libs mariadb-server mariadb-devel
rm -rf /etc/my*
rm -rf /var/lib/mysql
rm -rf /var/log/mysql*

添加用户
useradd -s /sbin/nologin mysql


安装包 yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel


MySQL 手册: https://dev.mysql.com/doc/refman/

软件下载地址:
MySQL: https://dev.mysql.com/downloads/mysql/
Operating System: Source Code
OS Version: Generic Linux
tar -zxf mysql-boost-5.7.33.tar.gz
cd mysql-5.7.33

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DSYSCONFDIR=/etc \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DEXTRA_CHARSETS=all \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNODB_MEMCACHED=1 \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_ZLIB=system \
-DWITH_BOOST=boost \
-DENABLED_LOCAL_INFILE=1 \
-DENABLED_PROFILING=ON \
-DWITH_SYSTEMD=1

 

/********************** 不完整,待完善 ************************************/
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ mysql安装目录
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ mysql.sock路径
-DSYSCONFDIR=/etc \ mysql配置文件目录
-DDEFAULT_CHARSET=utf8 \ 默认的字符集为utf8
-DDEFAULT_COLLATION=utf8_general_ci \ 默认排序规则
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ 储存引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ 储存引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ 储存引擎
-DENABLE_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \ 数据库文件存放位置
-DEXTRA_CHARSETS=all \ 启用额外的字符集类型
-DMYSQL_TCP_PORT=3306 \ TCP端口
-DWITH_DEBUG=OFF \ 禁用debug
-DWITH_READLINE=1 \ 启用readline库支持(提供可编辑的命令行)
-DWITH_EMBEDDED_SERVER=1 \ 编译嵌入式服务器支持
-DWITH_ZLIB=system \ 启用libz库支持(zib、gzib相关)
-DENABLE_DTRACE=OFF \
-DWITH_BOOST=boost \ 指定boost
-DWITH_SYSTEMD=1 支持systemctl

/**********************************************************/


/usr/bin/ld: cannot find -lzlib
查看详细信息 ld -lzlib --verbose
查到的组件名去除 lib,进行查找,如 libzlib.so,去除lib 为 libz.so;
查找 find / -name libz.so*;
查找结果
/usr/lib64/libz.so.1
/usr/lib64/libz.so.1.2.7
/usr/lib64/libz.so
为 /usr/lib64/libz.so.1.2.7 创建软链接:
ln -s /usr/lib64/libz.so.1.2.7 /usr/lib/libzlib.so

make
make install

cd /usr/local/mysql/
chown -R mysql:mysql .

初始化数据库
初始化:
./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
* --datadir目录比较为空,--basedir --datadir 必须和/etc/my.cnf 配置的目录一致

*** 提示 my.cnf (参考底部)中所配置文件提前创建好,并将用户设置为mysql,可以避免很多坑。。。
创建my.cnf中pid-file文件,例:
mkdir -R /var/run/mysqld/
chown -R mysql /var/run/mysqld/

复制启动脚本
#cp ./support-files/mysql.server /etc/init.d/mysqld

更改 mysqld.service 文件中的pid项;
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

刷新识别启动脚本文件 systemctl daemon-reload
启动数据库 systemctl start mysqld
如无法启动查看mysqld.service设置项 /usr/lib/systemd/system/mysqld.service

查看端口服务 netstat -anpt | grep 3306
添加开机启动 systemctl enable mysqld

设置登陆密码 ./bin/mysqladmin -u root -p password "123456"

写入环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
或 vim /etc/profile
PATH=/usr/local/mysql/bin:$PATH

重新加载 source /etc/profile

 

 my.cnf

[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
user = mysql
port = 3306
socket = /tmp/mysql.sock
pid-file = /var/run/mysqld/mysqld.pid

basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/log/mysql-error.log # 错误文件
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /usr/local/mysql/log/mysql-slow.log


key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
safe-updates

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

posted @ 2021-03-07 16:46  蓝晓焰  阅读(237)  评论(0编辑  收藏  举报