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

Recommend

Summary and analysis of commonly used Docker commands and examples

Table of contents 1. Container lifecycle manageme...

MySQL master-slave configuration study notes

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

Introduction to fourteen cases of SQL database

Data Sheet /* Navicat SQLite Data Transfer Source...

How to connect JDBC to MySQL 5.7

1. First prepare the MySQL and Eclipse environmen...

How to enable the slow query log function in MySQL

The MySQL slow query log is very useful for track...

Detailed installation and configuration of Subversion (SVN) under Ubuntu

If you are a software developer, you must be fami...

Write a publish-subscribe model with JS

Table of contents 1. Scene introduction 2 Code Op...

js realizes the dynamic loading of data by waterfall flow bottoming out

This article shares with you the specific code of...

Usage of Linux userdel command

1. Command Introduction The userdel (user delete)...

How to detect Ubuntu version using command line

Method 1: Use the lsb_release utility The lsb_rel...

Detailed explanation of writing and using Makefile under Linux

Table of contents Makefile Makefile naming and ru...

Provides helpful suggestions for improving website design

<br />Scientifically Design Your Website: 23...

Steps for Docker to build its own local image repository

1. Environment and preparation 1. Ubuntu 14.04 2....