Windows下MySQL多实例/主从复制/重置密码/WordPress主从配置

来源:互联网 发布:劳丽诗淘宝店叫什么 编辑:程序博客网 时间:2024/06/05 14:36

Windows创建MySQL多实例

安装MYSQL
  1. 运行mysql-installer-community-5.7.16.0.msi
  2. 选择组件
    1. MySQL Server 5.7.16 – X64

复制实例

  1. C:\ProgramData\MySQL\MySQL拷贝为MYSQL1MYSQL2文件夹
  2. 修改各文件夹中的my.ini
    1. my.ini
  3. 创建服务
      1. mysqld -install mysql1 --defaults-file="C:\ProgramData\MySQL\MySQL1\my.ini"
      2. mysqld -install mysql2 --defaults-file="C:\ProgramData\MySQL\MySQL2\my.ini"
  4. 启动服务
      1. net start mysql1
      2. net start mysql2
MySQL Master/Slave配置
  1. 主从机上使用相同的usr账户和密码并同时赋予REPLICATION SLAVEREPLICATION CLIENT权限,前者用于数据同步,后者用于监视SLAVE同步状况:
               GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO usr@'192.168.0.%' IDENTIFIED BY 'pwd';
   2. 将主服务器数据dump/export,然后在从数据中import/restore。如果使用Workbenchexportimport功能注意import的时候存储过程和方法因为不包含任何Scheme操作或被忽略,需要手动执行对应sql文件以进行创建。
      然后执行同步:mysqlreplicate --master=usr:pwd@192.168.0.1 --slave=user:pwd@192.168.0.2 --rpl-user=usr:pwd

错误及解决办法

  1. ERROR: The slave’s server_id is the same as the master.
将主服务器的my.ini配置中Server_id=1修改Server_id=2
  1. ERROR: Master must have binary logging turned on.

在从服务器的my.ini配置中启用二进制日志

# Binary Logging.
# log-bin
log-bin=mysql-bin
  1. ERROR: The slave’s UUID is the same as the master.

在从服务器数据文件夹Data中修改auto.cnf文件中的server-uuid

[auto]
server-uuid=b1a3dd23-edc7-11e6-81b8-480fcf275eaf

MySQL忘记root密码

  1. my.ini配置文件[mysqld]下增加skip-grant-tables并重启MySQL服务
  2. 执行如下SQL
use mysql;
update MySQL.user set authentication_string=password('rootpassword') where user='root' ;
  1. my.ini配置文件中的skip-grant-tables注释或删除并重启MySQL服务

Wordpress数据库主从复制配置

  1. 下载Wordpress插件HyperDB并解压缩
  2. db.php拷贝到wp-content文件夹中
  3. db-config.php拷贝到根目录与wp-config.php同级文件夹
  4. 修改db-config.php将只读数据库配置项host对应的值由DB_HOST修改为DB_SLAVE
  5. wp-config.php中增加配置define('DB_SLAVE', ‘salve db ip address');
0 0