CentOS7上Mysql8 更改数据存储路径(datadir)

1、停止服务

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

2、创建目录

cd /data
mkdir mysql
chown mysql:mysql mysql
cd mysql
cp -a /usr/local/mysql/data/* /data/mysql/
# chown -R -v mysql:mysql /data/mysql

3、修改my.cnf

[root@server01 mysql]# vi /usr/local/mysql/etc/my.cnf 

[mysql]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
[mysqld]
port = 3306
mysqlx_port = 33060
mysqlx_socket = /usr/local/mysql/data/mysqlx.sock
basedir = /usr/local/mysql
#datadir = /usr/local/mysql/data
#socket = /usr/local/mysql/data/mysql.sock
datadir = /data/mysql
socket = /data/mysql/mysql.sock
pid-file = /usr/local/mysql/data/mysqld.pid
log-error = /usr/local/mysql/log/error.log
#这个就是用之前的身份认证插件
default-authentication-plugin = mysql_native_password
#保证日志的时间正确
log_timestamps = SYSTEM

4、为mysql.sock加连接

[root@server01 mysql]# ln -s /data/mysql/mysql.sock /usr/local/mysql/data/

5、启动mysql

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

6、查看

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

Copyright (c) 2000, 2018, 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 global variables like '%datadir%';
+---------------+--------------+
| Variable_name | Value        |
+---------------+--------------+
| datadir       | /data/mysql/ |
+---------------+--------------+
1 row in set (0.03 sec)

mysql> 
posted @ 2021-01-05 13:41  星火撩原  阅读(1010)  评论(0编辑  收藏  举报