Change the default MySQL data directory with SELinux enabled
Change the default MySQL data directory with SELinux enabled
This is a short article that explains how you change the default MySQL data directory and adjust SELinux to account for the changes. The article assumes that you’re running either RHEL, CentOS, Scientific Linux or Fedora with SELinux enabled. This works with the most recent EL (6.2) version.
We’ll be doing this in the following order.
- Stopping the MySQL server
- Create a new data directory and move the content from the old data directory
- Correct the MySQL configuration file
- Adjust SELinux parameters to accept our new change
- Starting the MySQL server
Stopping the MySQL server
# service mysqld stop
Create a new data diretory and move the content from the old one
Creating a new data directory
# mkdir /srv/mysql/
# chown mysql:mysql /srv/mysql
Moving the original data files
# mv /var/lib/mysql/* /srv/mysql/
Correct the MySQL configuration file
Edit the my.cnf file for your distribution. In my example it’s located in the /etc/mysql/ directory. RHEL/CentOS/Scientific Linux put the my.cnf file directly in /etc by default.
# nano /etc/mysql/my.cnf
Change
datadir=/var/lib/mysql
to
datadir=/srv/mysql
and
socket=/var/lib/mysql/mysql.sock
to
socket=/srv/mysql/mysql.sock
and save the file.
Adjust SELinux parameters to accept our new change
Should the following command output “Permissive” or “Disabled” then you may skip the details for SELinux.
# getenforce
Run the semanage command to add a context mapping for /srv/mysql.
# semanage fcontext -a -t mysqld_db_t "/srv/mysql(/.*)?"
Now use the restorecon command to apply this context mapping to the running system.
# restorecon -Rv /srv/mysql
Starting the MySQL server
# service mysqld start
Verifying access and connectivity
$ mysql -u root -p
mysql> show databases;
If this is working, you’re up and running. Should you get a message that says
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
then add the following to your /etc/my.cnf
[client]
socket = /srv/mysql/mysql.sock
Optionally you can just use
$ mysql -u root -p --protocol tcp
to avoid connecting via the socket.
Change the default MySQL data directory with SELinux enabled的更多相关文章
- Change MYSQL data directory
		For example, change mysql data directory from /var/lib/mysql to /var/data/mysql Step1: Copy the /var ... 
- How To Move a MySQL Data Directory to a New Location on Ubuntu 16.04
		16 How To Move a MySQL Data Directory to a New Location on Ubuntu 16.04 PostedJuly 21, 2016 62.1kvie ... 
- 启动 mysql 失败 Warning:The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql'
		Warning:The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql' 这应该是某种情况下导致/usr/ ... 
- Mac下启动MySQL出现错误“the /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql' user”解决
		错误如下: Warring the /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql' user 这应该是某 ... 
- Warning:The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql'
		Mac OS X的升级或其他原因可能会导致MySQL启动或开机自动运行时 在MySQL操作面板上会提示“Warning:The /usr/local/mysql/data directory is ... 
- 启动mysql 失败,“Warning:The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql' ”
		一.Mac OS X的升级或其他原因可能会导致MySQL启动或开机自动运行时 在MySQL操作面板上会提示“Warning:The /usr/local/mysql/data directory is ... 
- MySQL Data Directory -- Creating file-per-table tablespaces outside the data directory
		Creating file-per-table tablespaces outside the data directory 一. Data Directory 1.应对情况 当数据库所在空间不足的时 ... 
- Warning the user/local/mysql/data directory is not owned by the mysql user
		sudo chown -RL root:mysql /usr/local/mysql sudo chown -RL mysql:mysql /usr/local/mysql/data sudo /us ... 
- 14.5.5 Creating a File-Per-Table Tablespace Outside the Data Directory
		14.5.5 Creating a File-Per-Table Tablespace Outside the Data Directory 创建一个File-Per-Table Tablespace ... 
随机推荐
- SpringCloud和Springboot
			SpringBoot+SpringCloud+SpringMVC+SpringData 我们把这种架构也称之为spring全家桶 什么是SpringCloudSpring Cloud是一系列框架的有序 ... 
- linux下误删目录文件后恢复神器extundelete
			原文链接:https://blog.51cto.com/wzlinux/2052835 参考:https://blog.csdn.net/cwg_1992/article/details/463100 ... 
- xsyProblem A: 密集子图(graph)
			f[i][S]三进制压缩表示最长路为i,0代表不在该集合,1代表不是最短路为i集合,2代表是最短路集合, 转移枚举i+1集合是那些, 乘以概率即可 预处理保证复杂度 #include<cstdi ... 
- react购物车
			import React, { Component } from 'react'; import {Tabs} from './Tabs' import 'whatwg-fetch' im ... 
- python 贝叶斯算法
			自我理解贝叶斯算法也就是通过概率来判断C是属于A类还是B类,下面是具体代码(python3.5 测试通过) 文字流程解释一波 1 ) 加载训练数据和训练数据对应的类别 2) 生成词汇集,就是所有 ... 
- !!代码:baidu 分享
			改参数,可以改图标的尺寸:16x16.24x24.32x32 <!DOCTYPE html> <html> <head> <title></tit ... 
- Jquery中addClass方法不起作用的解决方案
			selected类是要在点击后添加上去的新样式,在点击后,发现没有变化,打开开发者工具,发现selected类已经添加成功了. 在这里没有显示成功的主要原因是后添加的样式表优先级更低,我暂时不清楚具体 ... 
- TensorFlow学习之二
			二.常用操作符和基本数学函数 大多数运算符都进行了重载操作,使我们可以快速使用 (+ - * /) 等,但是有一点不好的是使用重载操作符后就不能为每个操作命名了. 1 算术操作符:+ - * / % ... 
- C#、Unity 数据类型的默认值
			using System.Collections; using System.Collections.Generic; using UnityEngine; public class Main : M ... 
- MySQL中IN子查询会导致无法使用索引
			今天看到一个博客园的一篇关于MySQL的IN子查询优化的案例,一开始感觉有点半信半疑(如果是换做在SQL Server中,这种情况是绝对不可能的,后面会做一个简单的测试.)随后动手按照他说的做了一个表 ... 
