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 ...
随机推荐
- hash 在 perl 中的用法(转载)
Perl的数据结构中最有趣的一个特性是哈希(hash),它使得在数据片段之间建立键-值(key-value)关联成为可能.虽然这些哈希要远远比普通系统中以数字索引的数组用途更广,但是往往也会使初学者不 ...
- spring boot项目使用外部tomcat启动失败总结
1. springboot的tomcat使用外部提供的. dependency> <groupId>org.springframework.boot</groupId> ...
- c# 多态 虚方法
多态: 为了解决同一种指令,可以有不同行为和结果 在运行时,可以通过调用同一个方法,来实现派生类中不同表现. 虚方法——抽象类——抽象函数——接口 虚方法: 被virtual 关键字修饰的方法 叫做 ...
- 《Celeste》 开发者是如何精心制作“冲刺”的
转自:http://www.gameres.com/804804.html 简介与序曲 在Celesete里,许多细微的行动都是发生在转瞬之间的,甚至往往比你想象中还要“转瞬之间”. 这里是 [游戏机 ...
- Vue-cli3.0开发笔记
安装 npm install -g @vue/cli # OR yarn global add @vue/cli 版本为3.X vue --version 创建项目 vue create hello- ...
- UEditor (富文本编译器)
下载网址:https://ueditor.baidu.com/website/download.html 开发文档:http://fex.baidu.com/ueditor/
- Android倒计时实现
Android为我们封装好了一个抽象类CountDownTimer,可以实现计时器功能: /** * 倒数计时器 */ private CountDownTimer timer = new Count ...
- 【Python】pip国内安装源和yum恢复
豆瓣安装源 pip install packages -i http://pypi.doubanio.com/simple --upgrade --trusted-host pypi.doubanio ...
- 保持ssh连接长时间不断开的技巧
我经常用ssh连接服务器,过段时间不用, 需要恢复一下断开的连接, 原因是NAT防火墙喜欢对空闲的会话进行超时处理,以确保它们状态表的干净和内存的低占用率,因为 长时间保持连接, 会长期占用部分系统资 ...
- Python-反射getattr的应用
login.py #!/usr/bin/dev python# coding:utf-8 def index(): print u'欢迎访问xx网站首页' def login(): print u'登 ...