LAMP 架构——mariadb-10.2.6 源码安装

准备工作

因为 MariaDB 的二进制包镜像源在国外地址,所以预先下载了该包到本地物理机,使用 lrzsz 工具将该包上传至虚拟机 /usr/local/src 目录进行安装。

物理地址为(点击直接下载到物理机上):
https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz


[root@adailinux src]# yum install -y lrzsz		//安装lrzsz工具


[root@dl-001 ~]# cd /usr/local/src	//上传本地包到虚拟终端
[root@dl-001 src]# ls
[root@dl-001 src]# rz

[root@dl-001 src]# ls
mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz  mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

1, 解压二进制已编译包

[root@dl-001 src]# tar zxf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz 

2, 移动至 /usr/local/ 下

[root@dl-001 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
[root@dl-001 local]# cd mariadb/

3,初始化脚本,指定 basedir 和 datadir

// 这里跟mysql安装不同的地方是需要额外指定basedir

[root@dl-001 mariadb]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
Installing MariaDB/MySQL system tables in '/data/mariadb' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/local/mariadb//bin/mysqladmin' -u root password 'new-password'
'/usr/local/mariadb//bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'/usr/local/mariadb//bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr/local/mariadb/' ; /usr/local/mariadb//bin/mysqld_safe --datadir='/data/mariadb'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mariadb//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/

4,拷贝配置文件(按服务器内存选择,这里测试选择 my-small.cnf)

# 这里是实现mysql和mariadb同存于一个机器中的做法
# 如果你的主机内只有mariadb,那么直接复制到/etc命令下,命名为my.cnf也行;对于的basedir也同样修改即可
[root@dl-001 mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
[root@dl-001 mariadb]# vi /usr/local/mariadb/my.cnf 
//在[mysqld]下插入下面的内容
basedir=/usr/local/mariadb
datadir=/data/mariadb

5, 拷贝启动脚本至 /etc/init.d/ 目录下,并修改内容

[root@dl-001 mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
[root@dl-001 mariadb]# vi /etc/init.d/mariadb 
//修改内容
basedir=/usr/local/mariadb
datadir=/data/mariadb
confdir=$basedir/my.cnf    //新增

//并在下面启动项内添加--defaults-file选项加载指定的配置文件
$bindir/mysqld_safe --defaults-file="$confdir" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &

6, 启动脚本并验证是否成功

[root@dl-001 mariadb]# /etc/init.d/mariadb start
Reloading systemd:                                         [  确定  ]
Starting mariadb (via systemctl):                          [  确定  ]

[root@dl-001 mariadb]# ps aux | grep mysql
root       3466  0.5  0.1 115392  1736 ?        S    13:04   0:00 /bin/sh /usr/local/mariadb//bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/localhost.localdomain.pid
mysql      3588 12.7  5.7 1125028 57864 ?       Sl   13:04   0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb/ --datadir=/data/mariadb/ --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mariadb/localhost.localdomain.err --pid-file=/data/mariadb//localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root       3624  0.0  0.0 112676   972 pts/0    S+   13:04   0:00 grep --color=auto mysql