Linux Yum安装mysql的数据库迁移目录
前言:因公司数据库目录存储满了,无法加空间进行更换数据目录
Warning:更换数据目录之前先问一下有么有在用,或者又没用风险之类的,如果数据库有读写或者其他操作建议晚上进行操作。
1.停用MySQL数据库
[[email protected] ~]# systemctl stop mysqld
2.查看数据现存目录迁移至所需目录
[[email protected] ~]# cat /etc/my.cnf | grep datadir
datadir=/usr/local/mysql/data
[[email protected] ~]# cp -ar /usr/local/mysql/ /data/
3.修改MySQL的配置文件
[[email protected] ~]# 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软链接至原有目录(否则会出现启动失败的情况)
[[email protected] ~]# ln -s /data/mysql/mysql.sock /usr/local/mysql/
5.启动MySQL服务
[[email protected] ~]# systemctl start mysqld
6.查看服务状态是否正常
[[email protected] ~]# 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.
[[email protected] ~]# 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
[[email protected] ~]# netstat -anpt | grep mysqld
tcp6 0 0 :::3306 :::* LISTEN 37449/mysql
7.检查数据是否正常
[[email protected] ~]# 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)
原文地址:https://blog.51cto.com/13229718/2485331
时间: 2024-10-27 13:05:18