背景
在CentOS7下如果没有默认安装MySQL数据库,可以选择安装MariaDB,最新的版本现在是10
可以选择直接yum默认安装的方式
yum -y install mariadb
yum -y install mariadb-server
往往有种情况,你默认安装的MariaDB数据不在指定的数据盘下,导致默认情况下磁盘空间相对比较小,等系统运行一段时间后,会造成磁盘空间不够的尴尬境地,这时需要考虑迁移数据存储的位置
简单操作方案
1、关闭mariadb
systemctl stop mariadb;
2、在上图中,我们可以看到有一块数据磁盘1T,可以把MariaDB数据迁移到这个位置下
在/data 下创建一个存放数据库文件的目录/data/mariadb
3、数据库的原位置中/var/lib/mysql下,把这个目录拷贝过去。
cp -a /var/lib/mysql? ?/data/mariadb/
基础操作已经完成,下面重点是配置文件的修改,很多地方会让修改/etc/my.cnf 这个配置文件,但是打开一看后发现,是这样的:
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
重点看到没,最后一行 !includedir /etc/my.cnf.d
cd /etc/my.cnf.d/ #进入这个目录下,有3个默认的配置文件
我们需要修改的是:server.cnf 文件,在[mysqld]下,追加了2行配置文件socket= 和 datadir= ,指定到现在的数据目录下
#
# These groups are read by MariaDB server.
# Use it for ptions that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
socket=/data/mariadb/mysql/mysql.sock
datadir=/data/mariadb/mysql
#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
# This group is only read by MariaDB-10.2 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.2]
以上已经完成了全部的配置,systemctl start mariadb; 启动即可。
虽然是一个小小的改动,项目中遇到了迁移掉,点滴技术也值得我们技术人学习!
2019即将过去,2020已经到来,新的一年,技术不断前行!