MySQL
MySQL高可用配置
MySQL Slave状态参数详解
基于二进制日志文件的复制
使用全局事务标识符GTID复制
MySQL安装升级
MySQL RPM包安装参考
MySQL编译化安装参考
MySQL Server版本升级
MySQL 操作手册/说明
MySQL导入导出操作
库,表,字段的字符集修改方法
根据字段生成自定义SQL语句
MySQL查询流程概述
MySQL 常用脚本
MySQL数据库冷备脚本
MySQL内存占用分析
MySQL内存消耗分析
检查MySQL引起的高内存占用
InnoDB下的内存分析和优化计算
MySQL常见问题
MySQL告警:Aborted connection日志的分析
MySQL使用命令kill进程后出现killed死锁问题
从库重起初始化relaylog失败
安全插件Connection-Control导致无法登录的问题
MySQL性能优化
MySQL查询慢性能分析
本文档使用 MrDoc 发布
-
+
home page
MySQL编译化安装参考
> 说明: 编译化安装版本为5.7.36(GA) ## 下载地址 MySQL下载地址(内含boost): - https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.36.tar.gz 其他版本下载地址: - https://dev.mysql.com/downloads/mysql/ ## 编译安装 编译安装前的环境说明: 编译采用CentOS7.6版本编译,编译目标目录为`/data`目录,该目录可自定义。 ### 编译环境安装 安装编译环境,用于编译时所的所需指令 ```bash yum install wget vim yum install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make cmake ``` 配置MySQL用户及目标地址 ```bash mkdir -p /data/mysql/{depackage/librpm,inspackage,basedir/etc,binlog,datadir,logs,tmp,init/manage/{systemctl}} useradd -r mysql -M -s /bin/false cd /data/mysql/inspackage wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.36.tar.gz ``` ### 编译安装MySQL程序 ```bash tar -zxvf mysql-boost-5.7.36.tar.gz cd mysql-5.7.36/ cmake . \ -DWITH_BOOST=boost \ -DMYSQL_DATADIR=/data/mysql/datadir \ -DCMAKE_INSTALL_PREFIX=/data/mysql/basedir \ -DSYSCONFDIR=/data/mysql/basedir/etc \ -DEXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DEFAULT_CHARSET=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci \ -DWITH_EMBEDDED_SERVER=1 \ -DDOWNLOAD_BOOST=1 make -j 16 make install touch /data/mysql/basedir/etc/my.cnf chown mysql:mysql /data/mysql/* -R ``` ### 编写配置文件 ```bash tee /data/mysql/basedir/etc/my.cnf<< EOF [mysqld] port = 3306 bind-address = 0.0.0.0 user = mysql server-id = 129 skip-name-resolve basedir = /data/mysql/basedir datadir = /data/mysql/datadir pid-file = /data/mysql/tmp/mysqld.pid socket = /data/mysql/tmp/mysql.sock tmpdir = /data/mysql/tmp character_set_server = utf8mb4 slow_query_log = 1 long_query_time = 1 slow_query_log_file = /data/mysql/logs/slow.log log-error = /data/mysql/logs/error.log lower_case_table_names=1 #log-bin = /data/mysql/binlog/mysql-bin binlog_format = mixed expire_logs_days = 5 binlog_cache_size = 8M #要同步的数据库 #binlog-do-db = mysql #不需要同步的数据库 #binlog-ignore-db = mysql open_files_limit = 65535 max_connections = 1500 max_connect_errors = 6000 max_allowed_packet = 32M max_heap_table_size = 64M tmp_table_size = 128M table_open_cache = 512 read_buffer_size = 16M read_rnd_buffer_size = 64M sort_buffer_size = 64M join_buffer_size = 64M key_buffer_size = 384M thread_cache_size = 16 query_cache_type = 1 query_cache_size = 8M query_cache_limit = 2M default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_open_files = 4000 innodb_buffer_pool_size = 64M innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 64M innodb_log_file_size = 1024M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 [client] port = 53306 socket = /data/mysql/tmp/mysql.sock default-character-set = utf8mb4 EOF ``` 配置systemctl管理服务 ```bash tee /data/mysql/init/manage/systemctl/mysqld.service<< EOF [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://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=/data/mysql/basedir/bin/mysqld --defaults-file=/data/mysql/basedir/etc/my.cnf LimitNOFILE = 5000 Restart=on-failure #RestartPreventExitStatus=1 #PrivateTmp=false EOF ``` ### 配置初始化脚本 ```bash tee /data/mysql/init/init.sh<< EOF #!/bin/bash time=\$(date +%y%m%d) groupadd -g 1100 mysql useradd -g mysql -u 1100 -r mysql -M -s /bin/false proBin=\$(cat /etc/profile|grep '/data/mysql/basedir/bin') if [[ \$proBin == '' ]];then echo 'export PATH=/data/mysql/basedir/bin:\$PATH' >>/etc/profile; fi source /etc/profile . /etc/profile [ -f /usr/lib64/libmysqlclient.so.20 ] && mv /usr/lib64/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20.bak_\$time cp /data/mysql/basedir/lib/libmysqlclient.so.20 /usr/lib64/ if [[ -f /etc/init.d/mysqld.service ]]; then mv /etc/init.d/mysqld.service /etc/init.d/mysqld.service.bak_\$time; fi if [[ -f /usr/lib/systemd/system/mysqld.service ]]; then mv /usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/mysqld.service.bak_\$time; fi if [[ -f /data/mysql/init/manage/service/mysqld.service ]]; then cp /data/mysql/init/manage/service/mysqld.service /etc/init.d/mysqld.service; fi if [[ -f /data/mysql/init/manage/systemctl/mysqld.service ]]; then cp /data/mysql/init/manage/systemctl/mysqld.service /usr/lib/systemd/system/mysqld.service; fi #修改server-id,uuid,当使用主从使用,配置参数一致会导致无法启动 sed -i "s/server-id.*/server-id = \$[\$[RANDOM%99]+100]/g" /data/mysql/basedir/etc/my.cnf sed -i "s/server-uuid=.*/server-uuid=66eafb32-a34f-11eb-af0a-020017006b3\$(echo \$RANDOM|md5sum|cut -c 5)/g" /data/mysql/datadir/auto.cnf systemctl daemon-reload chown mysql.mysql /data/mysql -R . /etc/profile systemctl enable mysqld echo 'Already startup method has been added to the host.' echo -e "Start Command :\n systemctl start mysqld" EOF ``` ### 初始化数据库 ```bash /data/mysql/basedir/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql/basedir/ --datadir=/data/mysql/datadir ``` ### 执行初始化脚本 ``` bash /data/mysql/init/init.sh ``` 全部配置完毕
Nathan
Nov. 27, 2021, 3:37 p.m.
转发文档
Collection documents
Last
Next
手机扫码
Copy link
手机扫一扫转发分享
Copy link
Markdown文件
PDF文件
Docx文件
share
link
type
password
Update password