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 ...
随机推荐
- ThinkPHP模板的知识
php框架 一.真实项目开发步骤: 多人同时开发项目,协作开发项目.分工合理.效率有提高(代码风格不一样.分工不好) 测试阶段 上线运行 对项目进行维护.修改.升级(单个人维护项目,十分困难,代码风格 ...
- python3学习笔记四(列表1)
参考http://www.runoob.com/python3/python3-list.html 序列 python包含6种内建的序列:列表,元组,字符串,Unicode字符串,buffer对象和x ...
- jdk8 Metaspace 调优
简介 jdk8的元空间的初始大小是21M,如果启动后GC过于频繁,请将该值设置得大一些. 更多Meatspace内容见<Metaspace 之一:Metaspace整体介绍(永久代被替换原因.元 ...
- web--webstorm的一些常用快捷键
Webstorm的一些常用快捷键 下面是Webstorm的一些常用快捷键: Alt+回车 导入包,自动修正 1. ctrl + shift + n: 打开工程中的文件,目的是打开当前工程下任意目录 ...
- [UE4]Wrap Box流布局
一.Wrap Box的子控件可以根据Wrap Box的大小自动换行 1.Wrap Box.Inner Slot Padding:Wrap Box所有子控件留白,可以实现每个控件之间的间距都是相同,但是 ...
- μC/Probe尝鲜
μC/Probe 1.添加文件 2.配置probe_com_cfg.h 2.1.选择接口 #define PROBE_COM_CFG_RS232_EN DEF_ENABLED /* Configure ...
- Cache基本原理之:结构
转载自:https://www.jianshu.com/p/2b51b981fcaf Cache entries 数据在主存和缓存之间以固定大小的”块(block)”为单位传递,也就是每次从main ...
- sizeof的用法
因为对sizeof不是很了解,所以去查了博客啥的,发现还是有大学问的,以下对其用法进行总结. 参考:https://www.cnblogs.com/zhangyz/articles/4736758.h ...
- delete content on the right of cursor, Mac
delete content on the right of cursor, Mac It's not convenient to press Fn+delete to delete content ...
- !!代码:baidu 分享
改参数,可以改图标的尺寸:16x16.24x24.32x32 <!DOCTYPE html> <html> <head> <title></tit ...