【kingsql分享】mysql数据库的本机迁移

如果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)

六、转载请注明出处,谢谢

@@@@@@@@@@@@@@@@@@@

洪卓辉 51CTO在线讲师

@@@@@@@@@@@@@@@@@@@

猜你喜欢

转载自blog.51cto.com/7654961/2327399