修改mysql数据目录

mysql在线默认安装后的数据目录为/var/lib/mysql
如果因为目录大小问题要修改数据存放目录,主要通过下面两个步骤就可以:
1. 停止mysql服务
2. 把/var/lib/mysql目录迁移到新目录,如/data01/mysqldata/mysql(注意新建目录权限)
3. 修改my.cnf相关目录参数,如:

[mysqld]
bind-address = 0.0.0.0
port        = 3306
socket      = /data01/mysqldata/mysql/mysql.sock
user    = mysql
basedir = /data01/mysqldata/mysql
datadir = /data01/mysqldata/mysql
pid-file = /data01/mysqldata/mysql/mysqld.pid
skip-external-locking
key_buffer_size = 64M

max_allowed_packet      = 256M
max_heap_table_size     = 256M
net_buffer_length       = 8K
sort_buffer_size        = 2M
join_buffer_size        = 4M
read_buffer_size        = 2M
read_rnd_buffer_size    = 16M

myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M

explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id   = 1

# log
log-bin = /data01/mysqldata/mysql/binlog/mysql-bin
binlog_cache_size       = 32M
max_binlog_cache_size   = 512M
max_binlog_size         = 512M
binlog_format           = mixed
log_output              = FILE
log-error               = mysql-error.log
slow_query_log          = 1
slow_query_log_file     = slow_query.log
general_log             = 0
general_log_file        = general_query.log
expire-logs-days        = 14

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /data01/mysqldata/mysql
innodb_data_file_path   = ibdata1:76M:autoextend
innodb_log_group_home_dir = /data01/mysqldata/mysql
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
event_scheduler = on
character-set-server=utf8
innodb_force_recovery=0
binlog_rows_query_log_events = on
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysql]
#
socket=/data01/mysqldata/mysql/mysql.sock
default-character-set   = utf8

[client]
socket=/data01/mysqldata/mysql/mysql.sock

4. 启动mysql

问题:
启动mysql时可能会报如下的错误:

2019-02-12 09:52:00 12764 [Note] InnoDB: Completed initialization of buffer pool
2019-02-12 09:52:00 12764 [ERROR] InnoDB: auto-extending data file /data01/mysqldata/mysql/ibdata1 is of a different size 768 pages (rounded down to MB) than specified in the .cnf file: initial 4864 pages, max 0 (relevant if non-zero) pages!
2019-02-12 09:52:00 12764 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
2019-02-12 09:52:00 12764 [ERROR] Plugin 'InnoDB' init function returned error.
2019-02-12 09:52:00 12764 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-02-12 09:52:00 12764 [ERROR] Unknown/unsupported storage engine: InnoDB
2019-02-12 09:52:00 12764 [ERROR] Aborting

解决办法:
删除原来的ibdata1、ib_logfile0、ib_logfile1文件
然后重新启动mysql

你可能感兴趣的:(MySQL,备份恢复)