共计 6539 个字符,预计需要花费 17 分钟才能阅读完成。
Centos7 编译安装 Mysql5.7
系统说明
系统:centos7
IP:192.168.1.4
MySQL 访问端口: 61920 #默认 3306 | |
软件包存放目录:/data/software | |
mysql 安装的目录:/data/mysql5.7/app | |
mysql 数据存放目录:/data/mysql5.7/data | |
mysql 数据库配置:/data/mysql5.7/etc |
1. 安装依赖
# yum install -y gcc gcc-c++ openssl openssl-devel ncurses-devel
2. 下载文件
# 备用下载: | |
3. 安装 CMake
编译 Mysql5.7 需要用到 CMake,没有 CMake 的先下载安装,官网 https://cmake.org/download/
cd /data/software | |
安装 CMake | |
tar -zxvf cmake-3.21.1.tar.gz | |
cd cmake-3.21.1 | |
./configure | |
make && make install |
4. 安装 Mysql5.7
tar -zxvf mysql-boost-5.7.34.tar.gz | |
cd mysql-5.7.34/ | |
mkdir -p /data/mysql5.7/data /data/mysql5.7/app /data/mysql5.7/etc | |
mkdir /var/run/mysqld | |
| |
新建 mysql 用户和 mysql 用户组: | |
groupadd mysql | |
useradd -M -g mysql -s /sbin/nologin/ mysql | |
chown -R mysql:mysql /data/mysql5.7 | |
| |
yum install -y |
开始 Cmake 编译 Mysql
# cmake . -DWITH_BOOST=/data/software/mysql-5.7.34/boost/boost_1_59_0 \ | |
-DCMAKE_INSTALL_PREFIX=/data/mysql5.7/app \ | |
-DMYSQL_DATADIR=/data/mysql5.7/data \ | |
-DDEFAULT_CHARSET=utf8mb4 \ | |
-DDEFAULT_COLLATION=utf8mb4_general_ci \ | |
-DEXTRA_CHARSETS=all \ | |
-DENABLED_LOCAL_INFILE=1 \ | |
-DMYSQL_USER=mysql \ | |
-DMYSQL_TCP_PORT=61920 | |
# make && make install |
5.MySQL 配置文件
default-character-set = utf8mb4 | |
[ | ]|
port = 61920 | |
datadir=/data/mysql5.7/data | |
skip-name-resolve | |
default-storage-engine = InnoDB | |
character-set-client-handshake = FALSE | |
character-set-server = utf8mb4 | |
collation-server = utf8mb4_unicode_ci | |
init_connect='SET NAMES utf8mb4' | |
server_id = 1 | |
binlog_format = row | |
gtid_mode = on | |
enforce-gtid-consistency = true | |
log_bin = on | |
log-slave-updates = on | |
slow_query_log = 1 | |
long_query_time = 2 | |
log_queries_not_using_indexes = 1 | |
slow_query_log_file = ${Mysql_path}/slow-${MYSQL_PORY}.log | |
relay_log_info_repository = TABLE | |
master_info_repository = TABLE | |
relay_log_recovery = on | |
relay_log_purge = 1 | |
log_bin_trust_function_creators = off | |
sync_binlog = 1 | |
explicit_defaults_for_timestamp=true | |
ft_min_word_len = 1 | |
lower_case_table_names = 1 | |
max_allowed_packet = 256M | |
max_connections = 1500 | |
max_connect_errors = 20 | |
back_log = 500 | |
open_files_limit = 65535 | |
interactive_timeout = 3600 | |
wait_timeout = 3600 | |
table_open_cache = 1024 | |
binlog_cache_size = 2M | |
tmp_table_size = 128M | |
max_heap_table_size = 16M | |
read_buffer_size = 1M | |
read_rnd_buffer_size = 8M | |
sort_buffer_size = 1M | |
query_cache_size = 64M | |
query_cache_limit = 1M | |
join_buffer_size = 16M | |
thread_cache_size = 64 | |
innodb_buffer_pool_size=2G | |
innodb_log_file_size = 256M | |
innodb_log_buffer_size = 4M | |
innodb_log_buffer_size = 3M | |
innodb_flush_log_at_trx_commit = 1 | |
innodb_data_file_path = ibdata1:10M:autoextend | |
innodb_log_files_in_group = 3 | |
innodb_open_files = 800 | |
innodb_file_per_table = 1 | |
innodb_write_io_threads = 8 | |
innodb_read_io_threads = 8 | |
innodb_purge_threads = 1 | |
innodb_lock_wait_timeout = 120 | |
innodb_strict_mode=1 | |
innodb_large_prefix = on | |
[ | ]|
quick | |
default-character-set = utf8mb4 | |
max_allowed_packet = 256M | |
[ | ]|
auto-rehash | |
default-character-set = utf8mb4"> /data/mysql5.7/etc/61920.cnf |
初始化数据库
初始化数据 | |
| |
启动数据库: | |
| |
查看 mysql 是否启动成功 | |
| |
初始化完成的时候会提示生成了一个临时的 Mysql root 密码,记住 | |
A temporary password is generated for root@localhost: sTi:!,BhL7=s | |
| |
|
7. 开机自启动 mysql 服务
echo"# 开机启动 mysql5.7" >> /etc/rc.local | |
echo "/data/mysql5.7/app/bin/mysqld_safe --defaults-file=/data/mysql5.7/etc/61920.cnf &" >> /etc/rc.local |
8. 添加环境变量
echo"export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:${Mysql_app}/bin" >> /etc/profile | |
source /etc/profile | |
mysql -V |
9. 开启防火墙
如果有防火墙则开启
firewall-cmd 和 iptables 选择其中一个,我这边用的是 iptables。# iptables | |
iptables -I INPUT -p tcp --dport 61920 -j ACCEPT | |
service iptables save | |
systemctl restart iptables.service | |
# firewall | |
firewall-cmd --zone=public --add-port=61920/tcp --permanent | |
firewall-cmd --reload |
10. 基本操作
进入实例 mysql 实例
# mysql -u root -hlocalhost -P"61920"-p"123456"
新增远程用户: root_mysql
# mysql> CREATE USER'root_mysql'@'%'IDENTIFIED BY'12345678'; | |
# mysql> GRANT all privileges ON * . * TO 'root_mysql'@'%' IDENTIFIED BY '123456'; | |
# mysql> GRANT ALL PRIVILEGES ON * . * TO 'root_mysql'@'%' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ; | |
# mysql> flush privileges; |
关闭实例
mysqladmin -uroot -hlocalhost -P"${MYSQL_PORY}"-p"$Mysql_Password" shutdown | |
mysqladmin -uroot -hlocalhost -P"61920" -p"123456" shutdown |
启动 mysql
# mysqld_safe --defaults-file=/data/mysql5.7/etc/61920.cnf &
SHELL 脚本
正文完
星哥玩云-微信公众号
