Home >Database >Mysql Tutorial >mysql用户权限分配及主从同步复制_MySQL

mysql用户权限分配及主从同步复制_MySQL

WBOY
WBOYOriginal
2016-06-01 13:04:151065browse

赋予wgdp用户查询权限: grant select on wg_dp.* to 'wgdp'@'%' IDENTIFIED BY 'weigou123'; grant all privileges on *.* to 'yangchao'@'%' IDENTIFIED BY 'weigou123' 查询mysql其他用户权限: show grants for wgdp; 取消wgdp用户权限: revoke all on *.* from wgdp; PS:grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。 权限范围: 1.select、insert、update和delete权限 允许你在一个数据库现有的表上实施操作,是基本权限
2.alter权限允许你使用ALTER TABLE
3.create和drop权限允许你创建新的数据库和表,或抛弃(删除)现存的数据库和表 如果你将mysql数据库的drop权限授予一个用户,该用户能抛弃存储了MySQL存取权限的数据库! mysql5.5后 mysql的配置文件my.cnf中的主从配置的一些字段已经被废弃,开启主从的步骤:

1.准备工作,有两个linux主机

master:10.209.112.58 mysql5.5 master 的用户名是root,无密码,

slave:10.46.169.62 mysql5.5 slave 的用户名是root,无密码,slave登录master进行同步的账号是wgdp_syc;

允许slave登录master:GRANT ALL PRIVILEGES ON *.* TO 'wgdp_syc'@'10.46.169.62' IDENTIFIED BY 'syc1qaz2wsx' WITH GRANT OPTION; flush privileges;

2.主: 配置master的my.cnf: [mysqld] #master configure server-id = 1 log-bin=mysql-bin binlog-do-db=master binlog-ignore-db=mysql #master configure datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock

maser的id应该是1,说明log目录,同步的数据库,不允许同步的数据库

然后在Master上增加一个账号专门用于同步,如下:
GRANT REPLICATION SLAVE ON *.* TO rep@192.168.74.227 IDENTIFIED BY 'hello';
如果想要在Slave上有权限执行"LOAD TABLE FROM MASTER" 或 "LOAD DATA FROM MASTER"语句的话,必须授予全局的 FILE 和 SELECT 权限:
GRANT FILE,SELECT,REPLICATION SLAVE ON *.* TO rep@192.168.74.227 IDENTIFIED BY 'hello';
接下来备份Master上的数据,首先执行如下SQL语句:
FLUSH TABLES WITH READ LOCK;
然后把同步的数据tar打包,然后scp到227那台机器上,解压,注意权限问题
整个步骤完成之后,执行
UNLOCK TABLES

3.从: 配置slave的my.cnf: [mysqld] #configure master-slave server-id=2 #master-host=192.168.74.225 #master-user=rep #master-password=hello replicate-ignore-db=mysql replicate-do-db=master #configure master-slave 注意到slave的配置里 master-host的三个字段被注释掉了,因为5.5以后已经废弃这个配置,这三个字段的设置通过登陆slave的mysql后,执行以下语句: mysql> CHANGE MASTER TO MASTER_HOST='10.209.112.58',MASTER_USER='wgdp_syc',MASTER_PASSWORD='syc1qaz2wsx',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=0; 4.启动主从 mysql后,通过下述命令检验是否有问题: 从库:mysql> SHOW SLAVE STATUS\G;
  1. Slave_IO_Running: yes
  2. Slave_SQL_Running: Yes 如此就算是差不多了 mysql数据库同步出错,跳过: mysql> slave stop; Query OK, 0 rows affected (0.01 sec) mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; Query OK, 0 rows affected (0.00 sec) mysql> slave start; Query OK, 0 rows affected (0.00 sec)
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn