二进制安装mariaDB

1.获取二进制安装包

获取二进制格式MariaDB安装包,可去官网下载.

因为是实验环境,所以选择了最新版.

mariadb-10.2.12-linux-x86_64.tar.gz


2.解压

解压到 /usr/local,并给解压出的文件夹创建软连接

]# tar xf mariadb-10.2.12-linux-x86_64.tar.gz -C /usr/local/
]# cd /usr/local/
]# ln -sv mariadb-10.2.12-linux-x86_64/ mysql
]# ll mysql
lrwxrwxrwx. 1 root root 29 Jan 23 10:33 mysql -> mariadb-10.2.12-linux-x86_64/


3.创建帐户

为mariaDB创建一个系统用户,属主为root,数组为mysql

]# groupadd -r mysql
]# cat /etc/group | grep mysql
mysql:x:985:
]# cd mysql

ll查看发现所有文件的属主属组都只显示id号

针对软连接,要用下面的方式修改其中的文件属性

]# chown -R root:mysql ./*
]# ll
total 180
drwxrwxr-x. 2 root mysql 4096 Nov 14 22:34 bin
......


4.准备文档目录

为了管理方便,专门指定并创建几个专用目录

存放数据库的目录/mdata/data

存放配置文件的目录/etc/mysql

]# mkdir -pv /mdata/data

修改这个目录的属主属组为mysql

]# useradd -r mysql -g mysql -s /bin/nologin
]# chown -R mysql.mysql /mdata
]# mkdir /etc/mysql


5.配置文件

mariaDB的主配置文件是/etc/my.cnf.其中include包含了/etc/my.cnf.d这个目录

]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

support-files/目录下有5个针对不同系统内存设置的配置文件模板

]# ls /usr/local/mysql/support-files/my-*
my-huge.cnf my-innodb-heavy-4G.cnf my-large.cnf my-medium.cnf my-small.cnf

其中

my-small.cnf适用于内存只有64M;

my-medium.cnf适用于内存只有256M;

my-large.cnf适用于内存只有512M;

my-huge.cnf适用于更大内存,如2G、4G;

my-innodb-heavy-4G.cnf适用于4G内存;


实验用主机有2g内存,所以使用my-huge.cnf

把my-huge.cnf复制到自定义配置文件目录下并重命名为my.cnf,并在[mysqld]代码块中添加内容

]# cp support-files/my-huge.cnf /etc/mysql/my.cnf
]# vim /etc/mysql/my.cnf
datadir = /mdata/data #指定数据库目录
skip_name_resolve = ON #忽略反解主机名
innodb_file_per_table = ON #开启独立表空间,默认是所有数据库放在同一个文件中,ON的话会把每个数据库单独放一个文件


6.创建数据库文件

必须在/usr/local/mysql目录下操作,否则会报错

]# cd /usr/local/mysql
]# ./scripts/mysql_install_db --datadir=/mdata/data --user=mysql

7.创建日志文件

]# touch /var/log/mysqld.log
]# chown mysql:mysql /var/log/mysqld.log 


8.准备服务脚本,启动服务

先通过support-files/mysql.server 启动mysql

./support-files/mysql.server start

成功后,通过ps命令查看

]# ps -ef|grep mysql

找到--pid-file=/mdata/data/centos7.qt.pid字样 记住pid路径和名称/mdata/data/centos7.qt.pid

在/usr/lib/systemd/system目录下增新建mysql.service,内容如下

]# vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=Mysql
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/mdata/data/centos7.qt.pid
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=false
[Install]
WantedBy=multi-user.target
PIDFile=/mdata/data/centos7.qt.pid  #就是跟上上面记录的内容


执行重新扫描,加载有变化的单元,使服务生效,之后便可以通过systemctl操作

]# systemctl daemon-reload
]# systemctl start mysql


9.进行安全初始化设置

运行脚本

]# /usr/local/mysql/bin/mysql_secure_installation


10.设置环境变量

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


11.启动mysql

]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.2.12-MariaDB-log MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> 
posted @ 2018-01-29 20:09  QuintinX  阅读(322)  评论(0编辑  收藏  举报