Solution to changing the data storage location of the database in MySQL 5.7

Solution to changing the data storage location of the database in MySQL 5.7

As the data stored in the MySQL database gradually increases, the original storage space has been filled up, resulting in MySQL being unable to connect. Therefore, it is necessary to change the location where the data is stored. Here are some steps in the process. Make a note to check back later.

1. Modify the directory where mysql data is stored

There are two places to modify, one of which is to modify the datadir in the /etc/my.cnf file. By default:

datadir=/var/lib/mysql

Because my /data/ directory is relatively large, I changed it to:

datadir=/data/mysql/

Also modify the /etc/init.d/mysqld file and change datadir=”$result” to:

datadir="/data/mysql"

2. Stop the mysql service

service mysql stop

3. Create a new data storage directory

mkdir /data/mysql

4. Move the data to the new database storage directory

mv /usr/local/mysql/data/* /data/mysql

Here is a little additional knowledge: the data files of the innoDB engine and the MyISAM engine are different.

For the MyISAM engine, data files are stored in the corresponding database folders under the "/var/lib/mysql" directory as three files: "*.frm", "*.MYD", and "*.MYI". Simply move these files to the new data storage directory.

For the innoDB engine, data is stored in the $innodb_data_home_dir” 的ibdata1 (usually), and the structure file exists in table_name.frm.

5. Modify the MySQL database directory permissions and configuration files

chown mysql:mysql -R /data/mysql/

6. Modify the socket

Modify socket in two places, /etc/my.cnf

socket=/data/mysql/mysql.sock

Create a connection file to /var/lib/mysql/mysql.sock

ln -s /data/mysql/mysql.sock /var/lib/mysql/mysql.sock

7. Restart mysql service

implement

service mysql restart

When I started reading and writing the database, I found the following problem:

Read and Write:

ERROR 1146 (42S02): Table ** doesn't exist

Create the table:

ERROR 1005 (HY000): Can't create table 'runoob_tbl' (errno: 13)

Solution:

In the /data/mysql directory, delete the ib_logfile* files so that the innoDB engine table will be normal.

Re-execute

mysql> REPAIR TABLE ***;

For tables with large amounts of data, this process may be slow. After the execution is completed, the MyISAM engine table is also normal.

MySQL related topics, friends who need it can refer to the following

Summary of database operation knowledge in MySQL

MySQL Getting Started Tutorial

Mysql error and solution

Mysql root password operation method

The above is the solution for changing the data storage location of the database in MySQL 5.7 that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank you very much for your support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Two ways of storing scrapy data in MySQL database (synchronous and asynchronous)
  • Python example of storing JSON-like data in MySQL
  • How to install MySQL 5.7 on Ubuntu and configure the data storage path
  • How to change the database data storage directory in MySQL
  • Detailed example of MySQL data storage process parameters
  • How to move mysql5.7.19 data storage location in Centos7
  • How to implement Mysql switching data storage directory
  • MySQL database architecture details
  • MySQL spatial data storage and functions

<<:  How to use Docker containers to implement proxy forwarding and data backup

>>:  Summary of 3 ways to lazy load vue-router

Recommend

Using HTML web page examples to explain the meaning of the head area code

Use examples to familiarize yourself with the mean...

Detailed explanation of how MySQL (InnoDB) handles deadlocks

1. What is deadlock? The official definition is a...

Drawing fireworks effect of 2021 based on JS with source code download

This work uses the knowledge of front-end develop...

Echart Bar double column chart style most complete detailed explanation

Table of contents Preface Installation and Config...

How to implement responsive layout in vue-cli

When we are doing front-end development, we will ...

Introduction to the use of html base tag target=_parent

The <base> tag specifies the default address...

A brief discussion on the Linux kernel's support for floating-point operations

Currently, most CPUs support floating-point units...

Example of how to configure nginx in centos server

Download the secure terminal MobaXterm_Personal F...

MySQL 5.7.19 winx64 free installation version configuration tutorial

mysql-5.7.19-winx64 installation-free version con...

Summary of commonly used tags in HTML (must read)

Content Detail Tags: <h1>~<h6>Title T...

Detailed explanation of CSS3 text shadow text-shadow property

Text shadow text-shadow property effects: 1. Lowe...

A brief introduction to web2.0 products and functions

<br />What is web2.0? Web2.0 includes those ...

In-depth explanation of the principle of MySQL Innodb index

introduction Looking back four years ago, when I ...