Database migration directory for mysql installation in Linux Yum

Because the company's database directory is full of storage, it is unable to add space to replace the data directory
Warning: before changing the data directory, ask whether it is in use or not. If the database is read-write or other operations, it is recommended to operate at night.
1. Disable MySQL database

[root@mysql ~]# systemctl stop mysqld

2. View the existing directory of data and migrate to the required directory

[root@mysql ~]# cat /etc/my.cnf | grep datadir
datadir=/usr/local/mysql/data
[root@mysql ~]# cp -ar /usr/local/mysql/ /data/

3. Modify MySQL configuration file

[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. Link the socket software to the original directory (otherwise, it will fail to start)

[root@mysql ~]# ln -s /data/mysql/mysql.sock /usr/local/mysql/

5. Start MySQL service

[root@mysql ~]# systemctl start mysqld

6. Check whether the service status is normal

[root@mysql ~]# systemctl status mysqld.service 
● mysqld.service - MySQL
   Loaded: loaded (/etc/init.d/mysql; enabled; vendor preset: disabled)
   Active: active (running) since Two 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 Month 0711:55:25 mysql systemd[1]: Starting MySQL...
4 Month 0711: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. Check whether the data is normal

[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)

Tags: Linux MySQL Database socket Oracle

Posted on Tue, 07 Apr 2020 07:16:08 -0700 by am_25