centos7 源码编译安装 MariaDB Server 10.5.6

  • 内容
  • 评论
  • 相关

正在启动更新系统 && 安装环境依赖包

yum install wget -y && wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo && yum -y update && \
yum -y install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake3 ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel && \
ln -s /usr/bin/cmake3 /usr/bin/cmake

创建用户 & 数据目录

mkdir -p /server/mysql
mkdir -p /server/data
useradd -s /sbin/nologin mysql
chown -R mysql:mysql /server/data

从网站下载mariadb源码包编译

cd /server/mysql

wget https://mirrors.ustc.edu.cn/mariadb//mariadb-10.5.6/source/mariadb-10.5.6.tar.gz

tar -xzvf mariadb-10.5.6.tar.gz

cd mariadb-10.5.6

cmake -DCMAKE_INSTALL_PREFIX=/server/mysql -DMYSQL_DATADIR=/server/data -DSYSCONFDIR=/etc -DWITHOUT_TOKUDB=1  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STPRAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWIYH_READLINE=1 -DWIYH_SSL=system -DVITH_ZLIB=system -DWITH_LOBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

make -j6 && make install

10.4 版本以上会报错。#chown 无法访问。。。。。。
我们需要对配置文件进行修改

#备份配置文件

cp /server/mysql/scripts/mariadb-install-db  mariadb-install-db.bak

#下面修改配置文件,消除错误提示

sed -i 's/chown 0 "$pamtooldir/#&/' scripts/mariadb-install-db && \
sed -i 's/chmod 04755 "$pamtooldir/#&/' scripts/mariadb-install-db && \
sed -i 's/chown $user "$pamtooldir/#&/' scripts/mariadb-install-db && \
sed -i 's/chmod 0700 "$pamtooldir/#&/' scripts/mariadb-install-db

/server/mysql/scripts/mysql_install_db --user=mysql --basedir=/server/mysql --datadir=/server/data 

编辑my.cnf 配置文件

vim /etc/my.cnf
[client]
#password   = your_password
port = 3306
socket      = /tmp/mysql.sock

[mysqld]
port = 3306
socket      = /tmp/mysql.sock
datadir = /server/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
slow-query-log-file=/server/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


innodb_data_home_dir = /server/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /server/data
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 2
innodb_write_io_threads = 2

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

移动服务脚本

cp /server/mysql/support-files/mysql.server /etc/init.d/mysql 

设置系统参数

touch /etc/profile.d/mysql.sh 

#写入参数

echo "export PATH=\$PATH:/server/mysql/bin/" >>/etc/profile.d/mysql.sh && \
source /etc/profile.d/mysql.sh 
#启动
service mysql start
chkconfig --add mysql
#开机启动
chkconfig mysql on 

#初始化数据库(请注意[点]后面有空格)

. /server/mysql/bin/mysql_secure_installation

测试数据库连接

mysql -hlocalhost -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.5.6-MariaDB-log Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)

MariaDB [(none)]> exit;
Bye

文末附上自动化脚本

本地下载

mariadbinit

脚本参数主要参数,请自行修改

#版本号涉及到文件下载,请注意
DBVERSION="10.5.6"
#安装目录
PREFIXDIR=/server/mysql
#数据目录
DDIR=/server/data
#配置文件
CONFIGFILE=/etc/my.cnf
#数据库程序运行用户
USER_GROUP="mysql"
#端口号请自行修改
PORT="3306"

使用方法:
sh mariadbinit.sh

评论

0条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注