MariaDB10在CentOS7系统下,迁移数据存储位置

背景

在CentOS7下如果没有默认安装MySQL数据库,可以选择安装MariaDB,最新的版本现在是10

<code>可以选择直接yum默认安装的方式
yum -y install mariadb
yum -y install mariadb-server/<code>
MariaDB10在CentOS7系统下,迁移数据存储位置

df -h查看空间使用情况

往往有种情况,你默认安装的MariaDB数据不在指定的数据盘下,导致默认情况下磁盘空间相对比较小,等系统运行一段时间后,会造成磁盘空间不够的尴尬境地,这时需要考虑迁移数据存储的位置

简单操作方案

1、关闭mariadb

<code>systemctl stop mariadb;/<code>

2、在上图中,我们可以看到有一块数据磁盘1T,可以把MariaDB数据迁移到这个位置下

在/data 下创建一个存放数据库文件的目录/data/mariadb

3、数据库的原位置中/var/lib/mysql下,把这个目录拷贝过去。

<code>cp -a /var/lib/mysql /data/mariadb//<code>

基础操作已经完成,下面重点是配置文件的修改,很多地方会让修改/etc/my.cnf 这个配置文件,但是打开一看后发现,是这样的:

<code>#
# 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/<code>

重点看到没,最后一行 !includedir /etc/my.cnf.d

<code>cd /etc/my.cnf.d/    #进入这个目录下,有3个默认的配置文件/<code>
MariaDB10在CentOS7系统下,迁移数据存储位置

/etc/my.cnf.d/ 的配置文件

我们需要修改的是:server.cnf 文件,在[mysqld]下,追加了2行配置文件socket= 和 datadir= ,指定到现在的数据目录下

<code>#
# 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]/<code>

以上已经完成了全部的配置,systemctl start mariadb; 启动即可。

虽然是一个小小的改动,项目中遇到了迁移掉,点滴技术也值得我们技术人学习!


2019即将过去,2020已经到来,新的一年,技术不断前行!


分享到:


相關文章: