赋予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 http://www.wfuyu.com/db/,权限才能生效。
权限范围:
1.select、insert、update和delete权限 允许你在1个http://www.wfuyu.com/db/现有的表上实行操作,是基本权限
2.alter权限允许你使用ALTER TABLE
3.create和drop权限允许你创建新的http://www.wfuyu.com/db/和表,或抛弃(删除)现存的http://www.wfuyu.com/db/和表 如果你将mysqlhttp://www.wfuyu.com/db/的drop权限授与1个用户,该用户能抛弃存储了MySQL存取权限的http://www.wfuyu.com/db/!
mysql5.5后 mysql的配置文件my.cnf中的主从配置的1些字段已被废弃,开启主从的步骤:
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目录,同步的http://www.wfuyu.com/db/,不允许同步的http://www.wfuyu.com/db/
然后在Master上增加1个账号专门用于同步,以下:
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的3个字段被注释掉了,由于5.5以后已废弃这个配置,这3个字段的设置通过登陆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 STATUSG;
-
Slave_IO_Running: yes
-
Slave_SQL_Running: Yes 如此就算是差不多了
mysqlhttp://www.wfuyu.com/db/同步出错,跳过:
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)