LNMP环境中的数据库迁移为独立的服务器
环境: centos 6.5 ip:192.168.0.118 ?nginx、php、mysql ? ? ? ? ?centos 6.5 ip:192.168.0.117 mysql 现在我们需要把数据库迁移到192.168.0.117机器上: 首先我们需要在118机器上备份数据库: mysqldump 最常用的备份工具: 逻辑备份:小于50G的数据量,4-6个小时ok 原理:将数据库的数据以逻辑的sql语句的方式导出? 物理备份:
下面我们以常用的逻辑来备份:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bqh |
| jyw |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
7 rows in set (0.06 sec)
mysql> quit
[[email?protected] mysql]# mysqldump -uroot -p123456 -A -B -X|gzip>/opt/bak_$(date +%F).sql.gz
-- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.
[[email?protected] mysql]# ll /opt/
总用量 348
-rw-r--r-- 1 root root 354461 6月 30 12:56 bak_2019-06-30.sql.gz
[[email?protected] mysql]# rm -rf /opt/bak_2019-06-30.sql.gz
[[email?protected] mysql]# mysqldump -uroot -p123456 -A -B -X --events|gzip>/opt/bak_$(date +%F).sql.gz #备份全库
[[email?protected] mysql]# ll /opt/
总用量 348
-rw-r--r-- 1 root root 354463 6月 30 13:00 bak_2019-06-30.sql.gz
[[email?protected] mysql]# mysqldump -uroot -p123456 -B -X wordpress|gzip>/opt/bak_wordpress.sql.gz #只备份指定的库
[[email?protected] mysql]# ll /opt/
总用量 544
-rw-r--r-- 1 root root 354463 6月 30 13:00 bak_2019-06-30.sql.gz
-rw-r--r-- 1 root root 199211 6月 30 13:01 bak_wordpress.sql.gz
注:Warning: Skipping the data of table mysql.event. Specify the --events option explicitly. 解决方法:mysqldump备份时加参数 --events 将备份的库scp到117机器上去: [[email?protected] mysql]# scp -rp -P22 /opt/bak_wordpress.sql.gz [email?protected]:/opt/
[email?protected]‘s password:
bak_wordpress.sql.gz 100% 195KB 194.5KB/s 00:00
[[email?protected] mysql]#
我们上117机器/opt/下查看是否推送过来了: 现在我们在117机器上恢复数据: [[email?protected] opt]# ll 总用量 188 -rw-r--r-- 1 root root 185857 6月 30 23:38 bak_wordpress.sql.gz drwxr-xr-x. 2 root root 4096 11月 22 2013 rh [[email?protected] opt]# gunzip bak_wordpress.sql.gz [[email?protected] opt]# ll 总用量 756 -rw-r--r-- 1 root root 766279 6月 30 23:38 bak_wordpress.sql drwxr-xr-x. 2 root root 4096 11月 22 2013 rh [[email?protected] opt]# less bak_wordpress.sql [[email?protected] opt]# mysql -uroot -p123456 <bak_wordpress.sql 我们进入数据库查看是否导入了: [[email?protected] opt]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 18
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000,2013,Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.00 sec)
mysql> use wordpress;
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_wordpress |
+-----------------------+
| bh_commentmeta |
| bh_comments |
| bh_links |
| bh_options |
| bh_postmeta |
| bh_posts |
| bh_term_relationships |
| bh_term_taxonomy |
| bh_terms |
| bh_usermeta |
| bh_users |
+-----------------------+
11 rows in set (0.00 sec)
mysql>
我们现在打开web博客试试: 原因是我们没做授权和配置wp-config.php,现在我们要做117机器上给予授权:对于web来讲,数据授权:增删改查即可。 mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | bqh-117 |
| root | bqh-117 |
| | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.01 sec)
mysql> grant select,insert,update,delete on wordpress.* to [email?protected]‘192.168.0.%‘ identified by ‘123456‘;
Query OK,0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK,0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+-----------+-------------+
| user | host |
+-----------+-------------+
| root | 127.0.0.1 |
| wordpress | 192.168.0.% |
| root | ::1 |
| | bqh-117 |
| root | bqh-117 |
| | localhost |
| root | localhost |
+-----------+-------------+
7 rows in set (0.00 sec)
mysql>
授权完后,我们需要修改wp-config.php配置文件:修改php连接文件 /** MySQL主机 */ define(‘DB_HOST‘,‘localhost‘); localhost更改为”远端数据库ip或者域名”?? #建议用域名 然后我们做hosts地址解析: 现在打开浏览器www.test.com ok! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |