MySQL Database Data directory Migration and configuration optimization under CentOS

Source: Internet
Author: User

Directory Migration
  1. Shutting down the database service

    service mysqld stop
  2. Copy Database

    mv  /var/lib/mysql /data/mysql# 或者使用cp -a复制# 这两个命令都会带权限到新目录去
  3. Modifying a configuration file/etc/my.cnf

    [mysqld]#datadir=/var/lib/mysql                      ------原系统默认路径datadir=/data/mysql      ------现有路径#socket=/var/lib/mysql/mysql.sock            ------原socket路径现socket=/data/mysql/mysql.sock                ------现有路径[mysqld_safe]socket=/data/mysql/mysql.sock                 -----现有路径[client]socket=/data/mysql/mysql.sock                 -----现有路径[mysql.server]socket=/data/mysql/mysql.sock                 -----现有路径
  4. Restart Service

    service mysqld start
  5. Problems that could not be started after the migration directory, it is possible that the SELinux ghost, can be set to permissive mode

    # getenforceEnforcing# setenforce 0# getenforcePermissive# setenforce 1 设置SELinux 成为enforcing模式# setenforce 0 设置SELinux 成为permissive模式

    or close selinux,vi/etc/selinux/config Modify selinux=disabled

    # This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:#     enforcing - SELinux security policy is enforced.#     permissive - SELinux prints warnings instead of enforcing.#     disabled - No SELinux policy is loaded.SELINUX=disabled# SELINUXTYPE= can take one of these two values:#     targeted - Targeted processes are protected,#     mls - Multi Level Security protection.SELINUXTYPE=targeted
Configuration Optimizations

Yum installed mysql default configuration does not seem to meet the requirements, mainly modify the following configuration

# 批量执行语句包的大小max_allowed_packet = 16M# innodb缓存,设置为服务器内存的 80%左右innodb_buffer_pool_size = 2048M# 锁等待超时时间innodb_lock_wait_timeout = 30# 0时表示关闭,1时表示打开,2表示只要select 中明确指定SQL_CACHE才缓存query_cache_type = 0# 最大连接数max_connections = 1024# 下面两个参数一起设定innodb_flush_log_at_trx_commit = 2sync_binlog = 1000# 表不区分大小写lower_case_table_names = 1

MySQL Database Data directory Migration and configuration optimization under CentOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.