将MySQL默认datadir修改为自己想要的路径
mysql 数据库的默认安装的路径在/var/lib/mysql,但是实际中,我们在安装时常常就需要定制安装数据库路径,比如/data/mysql,或者
mysql 数据库的默认安装的路径在/var/lib/mysql,但是实际中,我们在安装时常常就需要定制安装数据库路径,比如/data/mysql,或者/opt/mysql,通常是一个单独的一块盘或者分区,这样有利于性能调优和保护数据安全,同时也方便进行维护。
重新初始化mysql 的datadir方法是官方提供的perl脚本mysql_install_db。
perocna是一个优秀的mysql衍生版,以高性能为特色,这里以Percona 最新版5.6.12作为示范,迁移目标是/data/mysql
1、确保关闭了selinux,减少排障干扰。
事实证明,selinux是一大败笔,其规则不易维护,还常导致莫名其妙的问题。
2、安装percona
rpm -Uhv
yum install Percona-Server-server-56 --enablerepo=percona
3、创建目标目录
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
4、迁移命令
mysql_install_db --user=mysql --basedir=/usr --datadir=/data/mysql
5、为避免夜长梦多,干掉/var/lib/mysql
rm -rf /var/lib/mysql
6、创建合适的/etc/my.cnf,一定要指定datadir,其他具体配置没有定论,不过mysql5.6 默认的配置比较OK,推荐通过percona的工具在线配置一个https://tools.percona.com/
这里暂且贴一份,机器配置是6核,,16G内存
[mysql]
# CLIENT #
port = 3306
socket = /data/mysql/mysql.sock
default-character-set = utf8
[mysqld]
# GENERAL #
user = mysql
default_storage_engine = InnoDB
socket = /data/mysql/mysql.sock
pid-file = /data/mysql/mysql.pid
character-set-server = utf8
# MyISAM #
key_buffer_size = 32M
myisam_recover = FORCE,BACKUP
# SAFETY #
max_allowed_packet = 16M
max_connect_errors = 1000000
skip_name_resolve
# DATA STORAGE #
datadir = /data/mysql/
# BINARY LOGGING #
log_bin = /data/mysql/mysql-bin
expire_logs_days = 14
sync_binlog = 1
# CACHES AND LIMITS #
tmp_table_size = 32M
max_heap_table_size = 32M
query_cache_type = 0
query_cache_size = 0
max_connections = 500
thread_cache_size = 50
open_files_limit = 65535
table_definition_cache = 1024
table_open_cache = 2048
# INNODB #
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 2
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table = 1
innodb_buffer_pool_size = 10G
innodb_thread_concurrency = 12
thread_handling = pool-of-threads
#auto_increment_increment = 2
#auto_increment_offset = 0
# LOGGING #
log_error = /data/mysql/mysql-error.log
log_queries_not_using_indexes = 1
slow_query_log = 1
slow_query_log_file = /data/mysql/mysql-slow.log
7、启动mysql
12 chkconfig mysql on
service mysql start
至于报错,原因肯定有不止一百个,不解释了。按照上面的步骤执行就可以了,收集的常见报错如下,仅供参考:
A版,mysql启动报错
Starting MySQL...The server quit without updating PID file ,xxx.pid
B版,mysql_install_db 脚本运行出错
FATAL ERROR: Could not find my-default cnf, could not find my-default cnf, fata error my-default cnf, fatal error could not find my-default cnf, mysql_install_db my-default cnf error
另外,还有一个偷懒的办法,先创建/data/mysql,然后软链接到/var/lib/mysql,再安装mysql-server,这样反而可以规避一些常见错误。
推荐阅读:
MySQL备份和恢复具体实施
MySQL备份与恢复的三种方法总结
MySQL备份还原(视图、存储过程)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.
