Modify the default data directory of MySQL 8.0 (quick operation without configuration)

Modify the default data directory of MySQL 8.0 (quick operation without configuration)

Usage scenario: We use Alibaba Cloud and purchased a data disk separately (large space and can be used for backup). The MySQL 8.0 database is installed on the system disk by default. In order to consider security and space issues, we need to change the default database directory to another location (I use an SSD data disk here, by mounting)

Operating system: CentOS 7.6 Database: MySQL 8.0 To view more of my original articles, please click here

The default data directory location for MySQL 8.0 is: /var/lib/mysql

My target location is: /data/

Now let’s get started

1. First, we stop the MySQL 8.0 service and use the following command

[root@JasonSong ~]# sudo systemctl stop mysqld.service

Use the following command to check whether the service has stopped

[root@JasonSong ~]# sudo systemctl status mysqld.service
● mysqld.service – MySQL Server
  Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
  Active: inactive (dead) since Thu 2019-02-21 13:52:24 CST; 9s ago
   Docs: man:mysqld(8)
      http://dev.mysql.com/doc/refman/en/using-systemd.html
 Process: 6152 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
 Process: 6082 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 6152 (code=exited, status=0/SUCCESS)
  Status: "SERVER_SHUTTING_DOWN"

Feb 20 16:30:39 JasonSong systemd[1]: Starting MySQL Server...
Feb 20 16:30:50 JasonSong systemd[1]: Started MySQL Server.
Feb 21 13:52:21 JasonSong systemd[1]: Stopping MySQL Server...
Feb 21 13:52:24 JasonSong systemd[1]: Stopped MySQL Server.

2. Move the default data directory to the target location

[root@JasonSong ~]# mv /var/lib/mysql/ /data/

Soft link the target location to the original location and use the following command to create a soft link

[root@JasonSong ~]# ln -s /data/mysql /var/lib/

To check whether the link is successful, use the following command

[root@JasonSong ~]# ls -la /var/lib/mysql
lrwxrwxrwx 1 root root 11 Feb 21 14:00 /var/lib/mysql -> /data/mysql

After displaying the above information, you can start the MySQL service for testing.

[root@JasonSong ~]# sudo systemctl start mysqld.service
[root@JasonSong ~]# sudo systemctl status mysqld.service
● mysqld.service – MySQL Server
  Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
  Active: active (running) since Thu 2019-02-21 14:02:13 CST; 8s ago
   Docs: man:mysqld(8)
      http://dev.mysql.com/doc/refman/en/using-systemd.html
 Process: 21361 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 21379 (mysqld)
  Status: "SERVER_OPERATING"
  CGroup: /system.slice/mysqld.service
      └─21379 /usr/sbin/mysqld

Feb 21 14:02:12 JasonSong systemd[1]: Starting MySQL Server...
Feb 21 14:02:13 JasonSong systemd[1]: Started MySQL Server.

The above information is displayed, which means it is OK. To view more of my original articles, please click here.

This is the end of this article about changing the default data directory of MySQL 8.0 (quick operation without configuration). For more information about changing the default directory of MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to modify the data directory of MySQL 5.5 database under win2008 R2 server
  • Modify the MySQL 5.5 database data directory under Windows Server 2003
  • How to modify the mysql data directory under Win2008 r2
  • centos mysql modify database directory
  • How to modify the storage directory of Mysql database?

<<:  Detailed deployment of docker+gitlab+gitlab-runner

>>:  Vue calls the PC camera to realize the photo function

Blog    

Recommend

Docker's health detection mechanism

For containers, the simplest health check is the ...

Analysis of Mysql data migration methods and tools

This article mainly introduces the analysis of My...

Detailed explanation of samba folder sharing server configuration under centos

1. Introduction Recently I found that there are m...

Detailed Example of MySQL InnoDB Locking Mechanism

1. InnoDB locking mechanism The InnoDB storage en...

Implementation of Docker cross-host network (overlay)

1. Docker cross-host communication Docker cross-h...

Nginx server https configuration method example

Linux: Linux version 3.10.0-123.9.3.el7.x86_64 Ng...

CentOS 8 officially released based on Red Hat Enterprise Linux 8

The CentOS Project, a 100% compatible rebuild of ...

What is TypeScript?

Table of contents 1. JavaScript issues 2. Advanta...

Steps for importing tens of millions of data into MySQL using .Net Core

Table of contents Preliminary preparation Impleme...

MySQL master-slave configuration study notes

● I was planning to buy some cloud data to provid...

An article to quickly understand Angular and Ionic life cycle and hook functions

Table of contents Angular accomplish Calling orde...

JS implements a stopwatch timer

This article example shares the specific code of ...

Summary of MySql import and export methods using mysqldump

Export database data: First open cmd and enter th...