系统软件环境:Debian12,MariDB10.11.3
硬件环境:1037u+4GDDR3L+64Gmsata(装系统)+两个500G笔记本机械硬盘组成的Raid1
用默认安装的方式安装了mariaDB,但是由于怕64G的二手Msata固态硬盘坏掉,而且空间太小,所以就用两个闲置的2.5寸500G机械硬盘组了个Raid1.现在想把网站目录和数据库储存数据的目录迁移到这个Raid1.记录过程如下:
1、查询MariaDB数据存储目录的默认路径:
输入
mysql -u root -p
显示
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.11.3-MariaDB-1 Debian 12
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
输入
show variables like '%datadir%';
显示
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| datadir | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.003 sec)
输入quit,退出mysql
MariaDB [(none)]> quit
Bye
2、停止MariaDB服务
systemctl stop mysql
3、复制原数据库数据目录到新目录:
注意复制命令中 -p参数代表复制文件夹属性,-r参数代表复制整个文件夹及文件夹内的文件,即递归方式复制。
cp -pr /var/lib/mysql /mnt/raid1
4、修改/etc/mysql/mariadb.conf.d/50-server.cnf里的datadir路径
nano /etc/mysql/mariadb.conf.d/50-server.cnf
修改成(片段摘录):
# * Basic Settings
#
#user = mysql
pid-file = /run/mysqld/mysqld.pid
basedir = /usr
**#下面那句是我修改的:datadir=/mnt/raid1/mysql
datadir = /mnt/raid1/mysql**
#datadir = /var/lib/mysql
#tmpdir = /tmp
按ctrl+O保存,再按ctrl+x退出。
5、启动mysql服务
systemctl start mysql
显示:
root@1037u:~# systemctl status mysql
● mariadb.service - MariaDB 10.11.3 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled)
Active: active (running) since Fri 2023-10-06 12:32:27 CST; 2h 43min ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
至此,MariaDB更改数据存储目录成功。