1. 程式人生 > >【kingsql分享】mysql資料庫的本機遷移

【kingsql分享】mysql資料庫的本機遷移

如果mysql資料庫用著用著空間不夠了,那麼應該怎麼辦呢?
方法有很多,包含並不侷限於以下方法:

1.可以遷移到另外一套高效能伺服器上
2.如果是邏輯卷,可以擴大邏輯卷
3.新增新的大容量儲存空間,本機遷移

咱們今天就來演示一下第3種方法
比如添加了更大容量的儲存空間,然後mount上了,這個空間是/kingsql2

一、建立儲存目錄
[[email protected] ~]# mkdir -p /kingsql2/data/new
[[email protected] ~]# chown mysql.mysql -R /kingsql2

二、關閉資料庫
[[email protected]

~]# 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: ~)

三、“挪”一下
[[email protected] ~]# rsync -av /kingsql/database/mysql/data/ /kingsql2/data/new/

四、引數檔案改這個引數
datadir = /kingsql2/data/new

五、啟動之後,驗證一下引數
[[email protected] ~]# 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線上講師

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