CentOS 6 自定义单实例 二进制方式 安装mariadb-5.5.59

系统平台:

CentOS release 6.9 (Final)

内核 2.6.32-696.el6.x86_64

1.去官网下载适合的二进制包

http://mariadb.org/

mariadb-5.5.59-linux-x86_64.tar.gz

检查系统内是否安装了数据库。

#rpm -qa|grep MariaDB
#rpm -qa|grep mysql

2.创建mysql组和账号

#groupadd -g 500 mysql
#useradd -u 500 -g mysql -s /sbin/nologin -M mysql

3.解压包至/usr/local

#tar xvf mariadb-5.5.58-linux-x86_64.tar.gz -C /usr/local/

4.创建软链接mysql指向解压后的目录

#cd /usr/local/
#ln -s mariadb-5.5.58-linux-x86_64/ mysql

5.修改mysql文件夹所属者和所属组

#chown -R mysql.mysql mysql/

6.添加PATH至环境变量中

#echo 'PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile.d/mysql.sh

检查文件
#cat /etc/profile.d/mysql.sh


加载环境变量文件 并检查
#source /etc/profile.d/mysql.sh
#echo $PATH

7.创建数据库存放文件夹并修改权限

#mkdir -pv /data/mysqldb/3306
#chown -R mysql.mysql /data/mysqldb/
#chmod -R 770 /data/mysqldb

8.复制主配置文件my.cnf

这里先要确认下本机的内存多少,以便使用一个参考模板。

#grep memory support-files/*

找到适合本机内存的模板 image

本机内存为256M,所以选择了my-large.cnf这个配置文件

#cp support-files/my-large.cnf /data/mysqldb/3306/my.cnf

9.修改配置文件

#vim /data/mysqldb/3306/my.cnf

找到[mysqld]这一配置项, 添加我们定义好的数据库目录

[mysqld]
datadir         = /data/mysqldb/3306

10.安装数据库相关文件

# cd /usr/local/mysql

查看下安装程序的安装参数

#./scripts/mysql_install_db --help

必须在此文件夹内执行以下命令,否则会报以下错误

FATAL ERROR: Could not find ./bin/my_print_defaults

./scripts/mysql_install_db --datadir=/data/mysqldb/3306 --user=mysql --defaults-file=/data/mysqldb/3306/my.cnf --skip-name-resolve

参数说明 :指定此实例的配置文件,跳过DNS解析

出现2个OK即表示安装正常。 image

11.复制启动服务脚本至/etc/init.d目录

#cp support-files/mysql.server /etc/init.d/mysqld

12.修改启动脚本指定参数

因为本次安装自定义了非默认的位置,所以有些参数是需要对应修改的
#vim /etc/init.d/mysqld

a.找到这个位置,修改为创建的数据目录
if test -z "$datadir"
  then
     datadir=/data/sqldb/3306/data        #修改为这一行

b.找到这个位置,修改为新的配置文件路径。默认设定为/etc/my.cnf
# Try to find basedir in /etc/my.cnf
  conf=/data/mysqldb/3306/my.cnf          #修改为这一行

13.添加开机启动

#chkconfig --add mysqld
#chkconfig --list mysqld
mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

14.启动mysql服务

#service mysqld start
Starting MySQL.180123 00:58:39 mysqld_safe Logging to '/data/mysqldb/3306/centos6.hunk.teh.err'.
180123 00:58:39 mysqld_safe Starting mysqld daemon with databases from /data/mysqldb/3306
.                                                          [  OK  ]

15.检查确认

检查3306端口是否开启

#ss -ntl | grep 3306
LISTEN     0      50                        *:3306                     *:*

确认版本

#mysql -V
mysql  Ver 15.1 Distrib 5.5.59-MariaDB, for Linux (x86_64) using readline 5.1

16.进行安全配置

#/usr/local/mysql/bin/mysql_secure_installation

Enter current password for root 默认为空
Set root password   设置mysql root密码
Remove anonymous users  是否移除匿名用户登录
Disallow root login remotely    是否禁止root远程登录
Remove test database and access to it?  是否移除test数据和test账号
Reload privilege tables now?    是否立即更新权限
Thanks for using MariaDB!

17.客户端连接

#mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 11
Server version: 5.5.59-MariaDB MariaDB Server

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)]>

至此,MariaDB二进制方式安装完毕,适合快速部署。

请继续关注其他方式安装。

原文地址:https://www.cnblogs.com/momenglin/p/10587152.html