如果 MySQL 数据库用着用着空间不够了, 那么应该怎么办呢?
方法有很多, 包含并不局限于以下方法:
1. 可以迁移到另外一套高性能服务器上
2. 如果是逻辑卷, 可以扩大逻辑卷
3. 添加新的大容量存储空间, 本机迁移
咱们今天就来演示一下第 3 种方法
比如添加了更大容量的存储空间, 然后 mount 上了, 这个空间是 / kingsql2
一, 创建存储目录
- [root@linux01 ~]# mkdir -p /kingsql2/data/new
- [root@linux01 ~]# chown MySQL.MySQL -R /kingsql2
二, 关闭数据库
- [root@linux01 ~]# mysqladmin -uroot -p shutdown
- Enter password:
- 2018-12-06T03:31:47.583285Z mysqld_safe mysqld from pid file /kingsql/database/MySQL/mysqld.pid ended
[1]+ Done mysqld_safe (wd: /kingsql/database/MySQL)
(wd now: ~)
三,"挪" 一下
[root@linux01 ~]# rsync -av /kingsql/database/MySQL/data/ /kingsql2/data/new/
四, 参数文件改这个参数
datadir = /kingsql2/data/new
五, 启动之后, 验证一下参数
- [root@linux01 ~]# MySQL -uroot -p
- Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.7.21 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MySQL> show variables like 'datadir';
- +---------------+---------------------+
- | Variable_name | Value |
- +---------------+---------------------+
- | datadir | /kingsql2/data/new/ |
- +---------------+---------------------+
- 1 row in set (0.02 sec)
来源: http://www.bubuko.com/infodetail-2875599.html