主库授权备份账户 mysql> grant SELECT,RELOAD,SHOW DATABASES,SUPER,LOCK TABLES,REPLICATION CLIENT,SHOW VIEW,EVENT,FILE on *.* to backup@"localhost" identified by "MANAGER"; mysql> flush privileges;建立主从复制的用户名和密码,指定哪个IP地址用户使用这个用户可以访问主库 mysql> grant replication client,replication slave on *.* to "mysync"@"192.168.1.%" identified by "MANAGER"; mysql> flush privileges;
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | 248db | | 249db | | information_schema | | mysql | | performance_schema | | test | +--------------------+ 6 rows in set (0.00 sec)在248主机上创建表并插入数据 mysql> use 248db; Database changed mysql> create table aixuan1( -> id int(10) unsigned NOT NULL AUTO_INCREMENT, -> text varchar(20) NOT NULL DEFAULT "", -> PRIMARY KEY(id)) -> ENGINE=innodb AUTO_INCREMENT=1 -> DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.15 sec)
mysql> mysql> insert into aixuan1(text) values("aa"),("bb"),("cc"),("dd"),("ee"),("ff"); Query OK, 6 rows affected (0.02 sec) Records: 6 Duplicates: 0 Warnings: 0从库验证 MariaDB [(none)]> use 248db; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed MariaDB [248db]> show tables; +-----------------+ | Tables_in_248db | +-----------------+ | aixuan1 | +-----------------+ 1 row in set (0.00 sec)在249主机上创建表并插入数据 mysql> use 249db; Database changed mysql> create table helei1( -> id int(10) unsigned NOT NULL AUTO_INCREMENT, -> text varchar(20) NOT NULL DEFAULT "", -> PRIMARY KEY(id)) -> ENGINE=innodb AUTO_INCREMENT=1 -> DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.15 sec)
mysql> mysql> insert into helei1(text) values("aaa"),("bbb"),("ccc"),("ddd"),("eee"),("fff"); Query OK, 6 rows affected (0.02 sec) Records: 6 Duplicates: 0 Warnings: 0从库验证 MariaDB [248db]> use 249db; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed MariaDB [249db]> show tables; +-----------------+ | Tables_in_249db | +-----------------+ | helei1 | +-----------------+ 1 row in set (0.00 sec)