Environment CentOS7.4
mariadb 5.5
In principle, all mariadb installed from yum can be used
Because the paths of / var/lib/mysql and / etc/my.cnf are the same
The reason for this operation is that zabbix's history problem log has filled the disk, so you can only add a new hard disk and change the mysql storage path
----------------------------------------------------- split line------------------------------------------------------------------------------------------------
I have already attached this, but the steps are the same
First, add a hard disk,
View 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
Learn that the new one is / dev/sdb
Then fdisk /dev/sdb
Then enter np, enter 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 check the operation options, n is to create a new partition, then select the partition type, p is the primary partition, two times of carriage return is the default sector, which means to select all spaces under / dev/sdb, and finally press w to save
After the partition is divided, it is formatted. Here, we choose to format it in xfs format
mkfs.xfs -f /dev/sdb
Then create a new / data directory
Mount up
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
At this time, you can see that it has been mounted through df-th, and then you can set the power on mount
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
Just add the last line. Copy the first and second lines and paste them into the last line. Change the relevant ones. Now the hard disk has been mounted. If you are not sure, you can restart and try again. Next, change the storage path of mysql
Turn off mariadb first
systemctl stop mariadb
Change the location of the database (please refer to the location in the file / etc/my.cnf for the following path of yum installation, if it is source compiled or installed in other ways, ps: does the path of source compiled my.cnf also change? Then find / -name my.cnf yourself)
CP - A / var / lib / MySQL / data - A is the permission to keep the file folder
[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]#
Then?
vim /etc/my.cnfÂ
[mysqld] #datadir=/var/lib/mysql datadir=/data/mysql #socket=/var/lib/mysql/mysql.sock socket=/data/mysql/mysql.sock
Then start mariadb
systemctl start mariadb
Delete the previous one under / var/lib/mysql without error
Finally, if it is zabbix, there will be an error in such an operation, to the effect that you cannot connect to / var/lib/mysql/mysql.sock
At this time, Ln-S / data / MySQL / mysql.sock / var / lib / MySQL / mysql.sock is OK
If you need to install zabbix, you can read my previous articles. I'm too lazy to find links to put them here