概述
Mariadb
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可
MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB来代替MySQL的InnoDB。
环境
二 yum 安装
#2.1 设置yum源
在 /etc/yum.repos.d/CentOS-Base.repo 添加
[mariadb]
name = MariaDB
baseurl = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.2/centos7-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
#2.2 yum安装mariadb
安装的版本为:
yum install mariadb-server -y
systemctl enable mariadb
systemctl start mariadb
#2.3查看是否开启
ss -tpnl |grep 3306
#刚安装完毕的数据库,默认是没有密码的,直接登陆
mysql -uroot -p
接下来
#2.4 初始化配置
mysql_secure_installation #安全初始化脚本,进行如下设置:
#无需输入,直接enter
#设置root密码,输入Y
#是否关闭匿名账户
#不允许root账户远程登陆, 选择Y
#移除测试数据库,这里选择Y
#重载权限
#配置完毕
#2.5 再次执行登陆
提示需要输入密码才可以登陆。
#查询数据库账户
三 源码安装
3.1 脚本进行
#!/bin/bash
#注明: 在centos下下进行安装的脚本,我是在centos7下进行测试的。
#当前目录
basepath=$(cd `dirname $0`; pwd)
#数据库安装目录
mariadb_install_dir="/usr/local/mysql"
#数据库数据库目录
mariadb_data_dir="/usr/local/mysql/data"
#数据库默认密码
dbrootpwd="123456"
#源码包地址,官网下载地址地址是:https://downloads.mariadb.org/
down_tar_gz="http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-10.2.23/source/mariadb-10.2.23.tar.gz"
#安装依赖
yum install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel libdb-cxx-devel glibc-static -y
#查看是否有mysql账户
id -u mysql >/dev/null 2>&1
[ $? -ne 0 ] && useradd -M -s /sbin/nologin mysql
#确认是否存在安装目录不存在,那么创建和更改权限
[ ! -d "${mariadb_install_dir}" ] && mkdir -p ${mariadb_install_dir}
mkdir -p ${mariadb_data_dir};chown mysql.mysql -R ${mariadb_data_dir}
#下载源码和安装
mkdir $basepath/file_mysql
wget -O $basepath/maridb.tar.gz $down_tar_gz
tar -zxvf $basepath/file_mysql/$mariadb.tar.gz -C $basepath/file_mysql
mv $basepath/file_mysql/mariadb* $basepath/filemysql/mariadb
cd $basepath/mariadb
#Cmake
cmake . -DCMAKE_INSTALL_PREFIX=${mariadb_install_dir}
-DMYSQL_DATADIR=${mariadb_data_dir}
-DSYSCONFDIR=/etc/
-DWITHOUT_TOKUDB=1
-DMYSQL_USER=mysql
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
#启动项添加
/bin/cp ${mariadb_install_dir}/support-files/mysql.server /etc/init.d/mysqld
sed -i "s@^basedir=.*@basedir=${mariadb_install_dir}@" /etc/init.d/mysqld
sed -i "s@^datadir=.*@datadir=${mariadb_data_dir}@" /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
# my.cnf
cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = ${mariadb_install_dir}
datadir = ${mariadb_data_dir}
pid-file = ${mariadb_data_dir}/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 7
log_error = ${mariadb_data_dir}/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = ${mariadb_data_dir}/mysql-slow.log
performance_schema = 0
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
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 = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 500M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF
#进行配置
${mariadb_install_dir}/scripts/mysql_install_db --user=mysql --basedir=${mariadb_install_dir} --datadir=${mariadb_data_dir}
#备份一份
[ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}
service mysqld start
[ -z "$(grep ^'export PATH=' /etc/profile)" ] && echo "export PATH=${mariadb_install_dir}/bin:$PATH" >> /etc/profile
[ -n "$(grep ^'export PATH=' /etc/profile)" -a -z "$(grep ${mariadb_install_dir} /etc/profile)" ] && sed -i "s@^export PATH=(.*)@export PATH=${mariadb_install_dir}/bin:1@" /etc/profile
. /etc/profile
${mariadb_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by "${dbrootpwd}" with grant option;"
${mariadb_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by "${dbrootpwd}" with grant option;"
${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.user where Password='';"
${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.db where User='';"
${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.proxies_priv where Host!='localhost';"
${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "drop database test;"
${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "reset master;"
rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona,alisql}*.conf
echo "${mariadb_install_dir}/lib" > /etc/ld.so.conf.d/mariadb.conf
ldconfig
/etc/init.d/mysqld restart
echo "安装完毕"
最后
以上就是幽默大米为你收集整理的yum和编译安装Mariadb三 源码安装的全部内容,希望文章能够帮你解决yum和编译安装Mariadb三 源码安装所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复