MariaDB-5.5安装与配置

OS:CentOS 7  MariaDB:5.5.60

一、准备

sudo yum install -y gcc gcc-c++ zlib-devel libaio-devel openssl cmake libncurses libevent-devel
sudo useradd -s /sbin/nologin -M mariadb
mkdir /project/mariadb-5.5.60 /project/mariadb-5.5.60/data /project/mariadb-5.5.60/tmp
mkdir /app
ln -s /project/mariadb-5.5.60 /app/mariadb
mkdir /source && cd /source
wget -q http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-5.5.60/source/mariadb-5.5.60.tar.gz
tar -zxvf mariadb-5.5.60.tar.gz
cd mariadb-5.5.60

二、安装

cmake . -DCMAKE_INSTALL_PREFIX=/application/mariadb-5.5.60 
-DMYSQL_DATADIR=/application/mariadb-5.5.60/data 
-DMYSQL_UNIX_ADDR=/application/mariadb-5.5.60/tmp/mysql.sock 
-DMYSQL_USER=mariadb
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii 
-DENABLED_LOCAL_INFILE=1 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_FAST_MUTEXES=1 
-DWITH_ZLIB=bundled 
-DWITH_READLINE=1 
-DWITH_EMBEDDED_SERVER=1
-DWITH_SSL=system

make && make install
(*注:重新配置 #rm CMakeCache.txt  #make clean)

三、配置

sudo cp /source/mariadb-5.5.60/support-files/my-large.cnf /etc/my.cnf
/etc/my.cnf 部分配置:
------
[client]
port=3306
socket=/app/mariadb/tmp/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user=mariadb
port=3306
socket=/app/mariadb/tmp/mysql.sock
basedir=/app/mariadb
datadir=/app/maraidb/data
[mysqld_safe]
log-error=/app/mariadb/data/mysql.err
pid-file=/app/mariadb/tmp/mysqld.pid
------

mariadb.sh 启动脚本
------
#!/bin/bash
port=3306
mysql_user="root"
mysql_pwd="***"
cmdpath="/app/mariadb/bin"
mysql_sock="/app/mariadb/tmp/mysql.sock"

#start
function_start_mariadb()
{
        if [ ! -e "mysql_sock" ];then
                printf "Starting MariaDB...\n"
                /bin/bash ${cmdpath}/mysqld_safe 2>&1 >/dev/null &
        else
                printf "MariaDB is running...\n"
                exit
        fi
}

#stop
function_stop_mariadb()
{
        if [ ! -e "$mysql_sock" ];then
                printf "MariaDB is stopped...\n"
                exit
        else
                printf "Stopping MariaDB...\n"
                ${cmdpath}/mysqladmin -u ${mysql_user} -S /app/mariadb/tmp/mysql.sock shutdown
        fi
}
#restart
function_restart_mariadb()
{
        printf "Restarting MariaDB...\n"
        function_stop_mariadb
        sleep 5
        function_start_mariadb
}

case $1 in
start)
        function_start_mariadb
;;
stop)
        function_stop_mariadb
;;
restart)
        function_restart_mariadb
;;
*)
        printf "Usage: { start|stop|restart }\n"
esac
------

初始化数据库文件
sudo /app/mariadb/bin/mysql_install_db --basedir=/app/mariadb --datadir=/app/maraidb/data --user=mariadb

sudo chown -R mariadb.mariadb /app/mariadb/*
sudo echo 'export PATH=/app/mariadb/bin:$PATH' >>/etc/profile

将服务交于systemctl管理
sudo vim /usr/lib/systemd/system/mariadb.service
------
[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target

[Service]
Type=forking
ExecStart=/app/mariadb/data/mariadb.sh start
ExecStop=/app/mariadb/data/mariadb.sh stop
Restart=always

[install]
WantedBy=muli-user.target
;Alias=mysql.service
------

 

你可能感兴趣的:(MariaDB)