共计 4127 个字符,预计需要花费 11 分钟才能阅读完成。
虽然网上有很多 Linux 下的 LNMP 一键安装包,可以直接安装集成环境。但是有时候我们需要单独的安装 mariadb,则可以使用下面的脚本来安装。
# 一键 CMAKE 编译安装 mariadb-10.0.12
# 安装到 /usr/local/mariadb
# 数据目录为 /data/mysql
# my.cnf 文件是我自己修改的
一键安装包的文件目录结构如下:
我们只要自己将下面的文件组合成上图的结构,执行 sh install.sh 脚本即可完成安装。
install.sh 脚本内容如下:
#!/bin/bash
# Date: 2016/08/03
# Author: Lee
# 一键 CMAKE 编译安装 mariadb-10.0.12
# 安装到 /usr/local/mariadb
# 数据目录为 /data/mysql
# my.cnf 文件是我自己修改的
echo -e “\033[32m 即将安装 MariaDB 到 /usr/local \033[0m”
echo -e “\033[32m 数据目录为 /data/mysql, 请确保有足够的空间存放数据 \033[0m”
echo -e “\033[31m 你有 10 秒钟的时间取消该操作 ( 按 ctrl+ c 取消)\033[0m”
echo
sleep 10
if [! -f src/mariadb-10.0.12.tar.gz];then
echo -e “\033[31m 不存在 mariadb-10.0.12 包.Quit\033[0m”
exit
fi
tar xf src/mariadb-10.0.12.tar.gz -C src/
cd src/mariadb-10.0.12
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DSYSCONFDIR=/etc \
-DWITH_ARIA_STORAGE_ENGINE=1 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=bundled \
-DWITH_ZLIB=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1
make && make install
groupadd mariadb
useradd -r -s /sbin/nologin -g mariadb mariadb
chown mariadb.mariadb /usr/local/mariadb -R
cp /usr/local/mariadb/support-files/mysql.server /etc/init.d/mariadb
chmod +x /etc/init.d/mariadb
\cp ../../my.cnf /etc/my.cnf
mkdir /data/mysql -p
chown mariadb.mariadb /data/mysql -R
/usr/local/mariadb/scripts/mysql_install_db –user=mariadb –basedir=/usr/local/mariadb –datadir=/data/mysql
/etc/init.d/mariadb start
if ss -lnt|grep 3306 –color=auto ;then
echo -e “\033[32mMariaDB 已启动.\n 默认 server-id 为 1. \033[0m”
echo -e “\033[31m 在主从或主主复制环境下请修改 server-id 并重启 MariaDB!!\033[0m”
fi
优化后的 my.cnf 配置文件:
[client]
user = root
#password = your_password
port = 3306
socket = /tmp/mysql.sock
[mysql]
default_character_set = utf8
prompt = [\d] >
[mysqld]
####basic####
user = mariadb
port = 3306
socket = /tmp/mysql.sock
datadir = /data/mysql/
basedir = /usr/local/mariadb/
pid_file = /var/run/mysql.pid
default_storage_engine = InnoDB
# others setting
skip_name_resolve = ON
skip_external_locking
character-set-server = utf8
# Timeout
connect_timeout = 20
wait_timeout = 14400
interactive_timeout = 14400
back_log = 500
myisam_recover
event_scheduler = ON
# Query Cache Setting
query_cache_type = OFF
query_cache_size = 0
# LOG Settings
server-id = 1
log-bin = mysql.bin
binlog_format = mixed
max_binlog_size = 1G
expire_logs_days = 10
binlog_cache_size = 8M
slow_query_log = ON
slow_query_log_file = /data/mysql/localhost_slow.log
long_query_time = 5
log_error = /data/mysql/localhost.error
log_warnings = 2
tmp_table_size = 32M
max_heap_table_size = 32M
max_connections = 1000
max_allowed_packet = 50M
thread_cache_size = 300
open_files_limit = 65535
# 可以设置的比 Open_tables 大一倍
table_open_cache = 4096
# InnoDB Optimize
innodb_file_per_table = ON
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
# innodb_buffer_pool_size 官方建议设置为内存大小的 50%~80%
innodb_buffer_pool_size = 4G
# 事务日志文件的大小
innodb_log_file_size = 512M
# Innodb 共享表空间的大小
innodb_data_file_path = ibdata1:1G:autoextend:max:2G
innodb_buffer_pool_instances = 8
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_buffer_pool_dump_at_shutdown = ON
innodb_buffer_pool_load_at_startup = ON
[mysqldump]
quick
max_allowed_packet = 48M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
Ubuntu 16.04 LTS 上安装 Nginx、MariaDB 和 HHVM 运行 WordPress http://www.linuxidc.com/Linux/2016-10/136435.htm
Ubuntu 16.04 Dockerfile 安装 MariaDB http://www.linuxidc.com/Linux/2016-09/135260.htm
Linux 系统教程:如何检查 MariaDB 服务端版本 http://www.linuxidc.com/Linux/2015-08/122382.htm
MariaDB Proxy 读写分离的实现 http://www.linuxidc.com/Linux/2014-05/101306.htm
Linux 下编译安装配置 MariaDB 数据库的方法 http://www.linuxidc.com/Linux/2014-11/109049.htm
CentOS 系统使用 yum 安装 MariaDB 数据库 http://www.linuxidc.com/Linux/2014-11/109048.htm
二进制安装 MariaDB 5.5.36 http://www.linuxidc.com/Linux/2017-02/140233.htm
Ubuntu 上如何将 MySQL 5.5 数据库迁移到 MariaDB 10 http://www.linuxidc.com/Linux/2014-11/109471.htm
[翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB http://www.linuxidc.com/Linux/2014-12/110048htm
Ubuntu 14.04(Trusty) 安装 MariaDB 10 数据库 http://www.linuxidc.com/Linux/2016-11/136833.htm
MariaDB 的详细介绍 :请点这里
MariaDB 的下载地址 :请点这里
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-02/141027.htm