前言:因公司數據庫目錄存儲滿了,沒法加空間進行更換數據目錄
Warning:更換數據目錄以前先問一下有麼有在用,或者又沒用風險之類的,若是數據庫有讀寫或者其餘操做建議晚上進行操做。
1.停用MySQL數據庫mysql
[root@mysql ~]# systemctl stop mysqld
2.查看數據現存目錄遷移至所需目錄sql
[root@mysql ~]# cat /etc/my.cnf | grep datadir datadir=/usr/local/mysql/data [root@mysql ~]# cp -ar /usr/local/mysql/ /data/
3.修改MySQL的配置文件數據庫
[root@mysql ~]# vim /etc/my.cnf #datadir=/usr/local/mysql/data #socket=/usr/local/mysql/mysql.sock datadir=/data/mysql/data socket=/data/mysql/mysql.sock
4.將socket軟連接至原有目錄(不然會出現啓動失敗的狀況)vim
[root@mysql ~]# ln -s /data/mysql/mysql.sock /usr/local/mysql/
5.啓動MySQL服務socket
[root@mysql ~]# systemctl start mysqld
6.查看服務狀態是否正常tcp
[root@mysql ~]# systemctl status mysqld.service ● mysqld.service - MySQL Loaded: loaded (/etc/init.d/mysql; enabled; vendor preset: disabled) Active: active (running) since 二 2020-04-07 11:55:26 CST; 1min 10s ago Process: 37229 ExecStop=/etc/init.d/mysql stop (code=exited, status=0/SUCCESS) Process: 37311 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCCESS) Main PID: 37318 (mysqld_safe) Tasks: 28 Memory: 151.5M CGroup: /system.slice/mysqld.service ├─37318 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/data --... └─37449 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data... 4月 07 11:55:25 mysql systemd[1]: Starting MySQL... 4月 07 11:55:26 mysql systemd[1]: Started MySQL.
[root@mysql ~]# ps -ef | grep mysqld mysql 37318 1 0 11:55 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/usr/local/mysql/data/mysqld.pid mysql 37449 37318 0 11:55 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/data/mysql/data/mysql.err --pid-file=/usr/local/mysql/data/mysqld.pid --socket=/data/mysql/mysql.sock root 37551 36896 0 11:56 pts/1 00:00:00 grep --color=auto mysqld
[root@mysql ~]# netstat -anpt | grep mysqld tcp6 0 0 :::3306 :::* LISTEN 37449/mysql
7.檢查數據是否正常ide
[root@mysql ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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 databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test | | wordpress | +--------------------+ 6 rows in set (0.00 sec)