mysql 8.0 改变数据目录和日志目录(一)

一、背景

原数据库数据目录:/data/mysql3306/data,日志文件目录:/data/mysql3306/binlog

变更后数据库目录:/mysqldata/3306/data,日志文件目录:/mysqldata/3306/binlog

 

二、操作过程

1、停止原库

[root@node01 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!

2、拷贝数据目录

[root@node01 ~]# cp -a /data/mysql3306/data/* /mysqldata/3306/data/

3、修改参数文件

原参数文件:

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
user=mysql
server_id=1
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql3306/data
log-error=/data/mysql3306/data/error.log
log_bin=/data/mysql3306/binlog/mysql-bin
gtid_mode=ON
enforce_gtid_consistency=ON
log_slave_updates=1

 

修改后参数文件:

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
user=mysql
server_id=1
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/mysqldata/3306/data
log-error=/mysqldata/3306/data/error.log
log_bin=/mysqldata/3306/binlog/mysql-bin
gtid_mode=ON
enforce_gtid_consistency=ON
log_slave_updates=1

 

4、启动数据库

[root@node01 ~]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS!

 

三、登录数据库验证
mysql> show variables like 'datadir';
+---------------+-----------------------+
| Variable_name | Value                 |
+---------------+-----------------------+
| datadir       | /mysqldata/3306/data/ |
+---------------+-----------------------+
1 row in set (0.00 sec)

mysql> show variables like '%log_bin%';
+---------------------------------+----------------------------------------+
| Variable_name                   | Value                                  |
+---------------------------------+----------------------------------------+
| log_bin                         | ON                                     |
| log_bin_basename                | /mysqldata/3306/binlog/mysql-bin       |
| log_bin_index                   | /mysqldata/3306/binlog/mysql-bin.index |
| log_bin_trust_function_creators | OFF                                    |
| log_bin_use_v1_row_events       | OFF                                    |
| sql_log_bin                     | ON                                     |
+---------------------------------+----------------------------------------+
6 rows in set (0.01 sec)

 
  

  

posted @ 2020-09-26 10:58  orcl  阅读(1862)  评论(0编辑  收藏  举报