*@DB01* yum install mariadb-server -y systemctl enable --now mariadb mysql_secure_installation
*@Web01* mysqldump -uroot -pcentos -A > all.sql scp all.sql root@192.168.99.101:/root/. *@DB01* mysql -uroot -psziit < all.sql mysql -uroot -psziit -e "show databases;"
a) 防火墙放行mysql端口 @DB01 firewall-cmd --add-service=mysql firewall-cmd --add-service=mysql rmanent b) Selinux允许http网络连接 @Web01 setsebool -P httpd_can_network_connect on c) 创建数据库用户并对Wordpress数据库授权 mysql -uroot -pcentos MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'192.168.99.%' identified by 'centos'; MariaDB [(none)]> flush privileges; d) 修改wp-config.php指向新的数据库服务器 vim /var/www/html/wp-config.php /** The name of the database for Press */ define( 'DB_NAME', 'wordpress' ); /** MySQL database username */ define( 'DB_USER', 'wordpress' ); /** MySQL database password */ define( 'DB_PASSWORD', 'centos' ); /** MySQL hostname */ define( 'DB_HOST', '192.168.99.101' );
访问Web01,发布测试文章,查看DB01上的wordpress数据库,能够查询到记录
DB01 MariaDB [wordpress]> use wordpress MariaDB [wordpress]> select * from wp_posts\G; post_title: 测试 post_excerpt: post_status: inherit comment_status: closed ping_status: closed post_password: post_name: 17-revision-v1 to_ping: pinged: post_modified: 2021-12-06 12:10:51