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!

 

三、登录数据库验证

[root@node01 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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 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)

 

  

mysql 8.0 改变数据目录和日志目录

上一篇:Mysql--->PreparedStatement 查询报错


下一篇:Mysql 常用命令