环境 CentOS7.4
mariadb 5.5
原则上yum安装的mariadb都可以
因为/var/lib/mysql 和/etc/my.cnf的路径都是一样的
之所以要进行这个操作时因为zabbix的历史问题日志把磁盘写满了,只能新加一个硬盘把mysql存放路径改一改
-----------------------------------------------------------分割线------------------------------------------------------------------------------------------------
我这个是已经挂载好了,但是步骤都是一样的
首先添加一个硬盘,
查看 fdisk -l
[root@sm-zabbix mysql]# fdisk -l
Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d7265
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 10487807 4194304 82 Linux swap / Solaris
/dev/sda3 10487808 251658239 120585216 83 Linux
Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
了解到新增的为/dev/sdb
然后 fdisk /dev/sdb
然后依次输入np回车回车w
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-2147483647, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2147483647, default 2147483647):
Using default value 2147483647
Partition 1 of type Linux and of size 1024 GiB is set
[root@sm-zabbix mysql]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xfa020d7f.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
m查看操作选项,n是新建一个分区,然后选择分区类型,p是主分区,两下回车就是默认扇形区域,代表选择/dev/sdb下的所有空间,最后按w保存
分区分好之后就是格式化,这里我们选择格式化为xfs格式的
mkfs.xfs -f /dev/sdb
然后新建一个/data目录
挂载上去
mount -t xfs /dev/sdb /data
[root@sm-zabbix mysql]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 115G 4.7G 111G 5% /
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 8.9M 3.9G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sdb xfs 1.0T 62M 1.0T 1% /data
/dev/sda1 xfs 1014M 174M 841M 18% /boot
tmpfs tmpfs 783M 12K 783M 1% /run/user/42
tmpfs tmpfs 783M 0 783M 0% /run/user/0
此时通过df -TH就可以看到已挂载好了,然后就是设置开机挂载
vim /etc/fstab
UUID=08749ee0-0982-4b75-8d57-dd5b10543557 / xfs defaults 0 0
UUID=c71dd609-a108-4585-aa7f-b4bb1548e2d7 /boot xfs defaults 0 0
UUID=984a1a4e-6415-49cc-809e-5de22137e0ac swap swap defaults 0 0
/dev/sdb /data xfs defaults 0 0
把最后一行加上就是了,复制第一二行的然后粘贴到最后把相关的改一下就行了,至此挂载硬盘就已经完成,不放心的可以再重启试下,接下来开始变更mysql存放路径了
首先关掉mariadb
systemctl stop mariadb
把数据库放置的位置变一下(以下的yum安装的路径,如果是源码编译或者其他方式安装的,请参照/etc/my.cnf文件中的位置,ps:话说源码编译的my.cnf的路径是不是也变了? 那你find / -name my.cnf 自己找一找吧)
cp -a /var/lib/mysql /data # -a 是保留文件 文件夹的权限
[root@sm-zabbix ~]# cd /data/
[root@sm-zabbix data]# ll
total 0
drwxr-xr-x 5 mysql mysql 177 Jan 18 15:16 mysql
[root@sm-zabbix data]#
然后
vim /etc/my.cnf
[mysqld]
#datadir=/var/lib/mysql
datadir=/data/mysql
#socket=/var/lib/mysql/mysql.sock
socket=/data/mysql/mysql.sock
然后启动mariadb
systemctl start mariadb
启动没报错就把之前/var/lib/mysql下的删掉吧
最后如果是zabbix的话这样一番操作会有报错,大意是不能连接到/var/lib/mysql/mysql.sock
这时候ln -s /data/mysql/mysql.sock /var/lib/mysql/mysql.sock 就可以了
如果需要安装zabbix的方法可以看看我之前的文章,链接我自己也懒得找链接放过来
来源:oschina
链接:https://my.oschina.net/u/3805108/blog/3159756