重要提醒:迁移之前一定备份一下数据库。
目标路径:/SQLDB
查看当前的路径:
mysql> show variables like '%dir%';
+-----------------------------------------+----------------------------------------+
| Variable_name | Value |
+-----------------------------------------+----------------------------------------+
| basedir | /usr/local/mysql/mysql/ |
| binlog_direct_non_transactional_updates | OFF |
| character_sets_dir | /usr/local/mysql/mysql/share/charsets/ |
| datadir | /usr/local/mysql/mysql/data/ |
| ignore_db_dirs | |
| innodb_data_home_dir | |
| innodb_log_group_home_dir | ./ |
| innodb_max_dirty_pages_pct | 90.000000 |
| innodb_max_dirty_pages_pct_lwm | 0.000000 |
| innodb_tmpdir | |
| innodb_undo_directory | ./ |
| lc_messages_dir | /usr/local/mysql/mysql/share/ |
| plugin_dir | /usr/local/mysql/mysql/lib/plugin/ |
| slave_load_tmpdir | /tmp |
| tmpdir | /tmp |
+-----------------------------------------+----------------------------------------+
15 rows in set (0.03 sec)
mysql> show variables like '%datadir%';
+---------------+------------------------------+
| Variable_name | Value |
+---------------+------------------------------+
| datadir | /usr/local/mysql/mysql/data/ |
+---------------+------------------------------+
1 row in set (0.00 sec)
在/etc/my.cnf中也可以看到数据文件的路径。
调整目标路径属主:
[root@newsqlaudit data]# chown -R mysql.mysql /SQLD
[root@newsqlaudit data]# service mysqld stop
Shutting down MySQL.... [ OK ]
复制当前的数据文件到目标路径中去:
[root@newsqlaudit data]# cp -r ./* /SQLDB/
[root@newsqlaudit SQLDB]# ls
auto.cnf ibdata1 ib_logfile1 mysql sys
ib_buffer_pool ib_logfile0 ib_logfile2 performance_schema sysbase
给目标路径的属主重新赋权一下:
chown -R mysql.mysql /SQLD
1、修改/etc/my.cnf中与原路径相关的内容:
datadir=/SQLDB
log-error=/SQLDB/mysqld.log
pid-file=/SQLDB/mysqld.pid
2、检查修改/etc/init.d/mysqld
如果里面涉及有datadir的参数,记得休整一下。
vim /etc/init.d/mysqld
datadir=/SQLDB
3、修改 mysqld_safe
vim /usr/local/mysql/mysql/bin/mysqld_safe
如果有datadir或者DATADIR也需要调整。有的版本没有的不需要。
启动数据库:
[root@newsqlaudit mysql]# service mysqld start
Starting MySQL..
阅读(2952) | 评论(0) | 转发(0) |