#!/bin/bash
#auto SourceCode Install mariadb
#by author linzc
#2020年7月2日 13:14:14
yum install -y wget lrzsz vim
echo "安装阿里base及epel源"
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
echo "清缓存"
yum clean all
yum makecache
echo "安装软件环境支持"
yum install -y wget lrzsz vim boost gcc ncurses-devel libaio bison gcc-c++ git cmake ncurses-devel openssl openssl-devel
echo "下载mariadb10.4.16源码包"
cd /usr/src/
wget -c https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.4.13/source/mariadb-10.4.13.tar.gz
echo "解压"
tar -zxvf mariadb-10.4.13.tar.gz
cd mariadb-10.4.13/
echo "创建mysql用户"
useradd -s /sbin/nologin -r mysql -M
echo "预编译"
cmake -j4 . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DMYSQL_DATADIR=/data/mariadb/ \
-DSYSCONFDIR=/usr/local/mariadb \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITHOUT_TOKUDB=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
echo "编译"
make -j4 && make install -j4
echo "查看安装目录"
ls /usr/local/mariadb/
echo "配置启动文件及权限等"
cd /usr/local/mariadb/
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
mkdir -p /data/mariadb/
chown -R mysql:mysql /data/mariadb
chown -R mysql:mysql /usr/local/mariadb/
echo "配置数据库主配置文件"
cat >/usr/local/mariadb/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mariadb/
datadir=/data/mariadb/
port=3306
pid-file=/data/mariadb/mysql.pid
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/data/mariadb/mysql.log
[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
EOF
echo -e "\033[32m数据库初始化\033[0m"
/usr/local/mariadb/scripts/mariadb-install-db --datadir=/data/mariadb/
echo "安装目录改回root权限"
chown -R root:root /usr/local/mariadb/
echo "数据目录权限改为mysql"
chown -R mysql:mysql /data/mariadb/
ls -l /data/mariadb/
echo "配置环境变量"
echo "export PATH=/usr/local/mariadb/bin:$PATH" >/etc/profile.d/mariadb.sh
. /etc/profile.d/mariadb.sh
echo "启动mysql"
/etc/init.d/mysqld restart
echo "查看进程"
ps -ef|grep mysql
netstat -tnlp
结果:
You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
安装目录改回root权限
数据目录权限改为mysql
total 122924
-rw-rw----. 1 mysql mysql 24576 Jul 2 13:04 aria_log.00000001
-rw-rw----. 1 mysql mysql 52 Jul 2 13:04 aria_log_control
-rw-rw----. 1 mysql mysql 972 Jul 2 13:04 ib_buffer_pool
-rw-rw----. 1 mysql mysql 12582912 Jul 2 13:04 ibdata1
-rw-rw----. 1 mysql mysql 50331648 Jul 2 13:04 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Jul 2 13:04 ib_logfile1
-rw-rw----. 1 mysql mysql 12582912 Jul 2 13:04 ibtmp1
-rw-rw----. 1 mysql mysql 0 Jul 2 13:04 multi-master.info
drwx------. 2 mysql mysql 4096 Jul 2 13:04 mysql
-rw-rw----. 1 mysql mysql 1864 Jul 2 13:04 mysql.log
-rw-rw----. 1 mysql mysql 6 Jul 2 13:04 mysql.pid
drwx------. 2 mysql mysql 20 Jul 2 13:04 performance_schema
drwx------. 2 mysql mysql 20 Jul 2 13:04 test
配置环境变量
启动mysql
Reloading systemd: [ OK ]
Restarting mysqld (via systemctl): [ OK ]
查看进程
root 42767 1 3 13:04 ? 00:00:00 /bin/sh /usr/local/mariadb//bin/mysqld_safe --datadir=/data/mariadb/ --pid-file=/data/mariadb/mysql.pid
mysql 42876 42767 27 13:04 ? 00:00:00 /usr/local/mariadb/bin/mysqld --basedir=/usr/local/mariadb/ --datadir=/data/mariadb/ --plugin-dir=/usr/local/mariadb//lib/plugin --user=mysql --log-error=/data/mariadb/mysql.log --pid-file=/data/mariadb/mysql.pid --socket=/tmp/mysql.sock --port=3306
root 42911 2197 0 13:04 pts/0 00:00:00 grep mysql
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1816/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1551/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1816/master
tcp6 0 0 :::3306 :::* LISTEN 42876/mysqld
tcp6 0 0 :::22 :::* LISTEN 1551/sshd
[root@localhost src]#
登陆
localhost src]# /usr/local/mariadb/bin/mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.4.13-MariaDB 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)]>