MySQL如何更改数据库数据存储目录详解


本文整理自网络,侵删。

前言

MySQL数据库默认的数据库文件位于/var/lib/mysql下,有时候由于存储规划等原因,需要更改MySQL数据库的数据存储目录。下文总结整理了实践过程的操作步骤。话不多说了,一起来看看吧

方法如下:

1:确认MySQL数据库存储目录

[root@DB-Server tmp]# mysqladmin -u root -p variables | grep datadir
 
Enter password: 
 
| datadir | /var/lib/mysql/

2:关闭MySQL服务

在更改MySQL的数据目录前,必须关闭MySQL服务。

方式1:

[root@DB-Server ~]# service mysql status
 
MySQL running (9411)[ OK ]
 
[root@DB-Server ~]# service mysql stop
 
Shutting down MySQL..[ OK ]
 
[root@DB-Server ~]# 

方式2:

[root@DB-Server ~]# /etc/rc.d/init.d/mysql status
 
MySQL running (8900)[ OK ]
 
[root@DB-Server ~]# /etc/rc.d/init.d/mysql stop
 
Shutting down MySQL..[ OK ]
 
[root@DB-Server ~]# 

3:创建新的数据库存储目录

[root@DB-Server ~]# cd /u01

[root@DB-Server u01]# mkdir mysqldata

4:移动MySQL数据目录到新位置

[root@DB-Server ~]# mv /var/lib/mysql /u01/mysqldata/

5:修改配置文件my.cnf

并不是所有版本都包含有my.cnf这个配置文件,在MySQL 5.5版本,我就找不到my.cnf这个配置文件, 而有些MySQL版本该文件位于/usr/my.cnf,如果/etc/目录下没有my.cnf配置文件,请到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个到/etc/并改名为my.cnf中。命令如下:

[root@DB-Server mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

编辑/etc/my.cnf文件,修改参数socket

MySQL 5.5 版本

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /u01/mysqldata/mysql/mysql.sock
 
# Here follows entries for some specific programs
 
# The MySQL server
[mysqld]
port = 3306
socket = /u01/mysqldata/mysql/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

阅读剩余部分

相关阅读 >>

mysql如何输出汉字信息

关于mysql互换表中两列数据方法的讲解

整理mysql常用查询语句(23种)

mysql中什么是存储过程

mysql解压缩安装的详细步骤(图文)

ddl语句的实例详解

navicat for mysql出现1064错误怎么办

mysql终端操作常用命令

mysql怎么删除数据表中的全部数据?

详解mysql集群:一主多从架构实现

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...