-
先使用mysql数据库 use mysql;
-
运行远程连接 GRANT ALL ON . TO 'root'@'%'; GRANT REPLICATION SLAVE ON . TO 'root'@'%';
-
查看所允许的访问地址
-
修改所允许的访问地址,即可 update user set host='%' where user='root';
-
查看密码加密方式 select host, user, plugin from user;
-
修改密码的加密方式 alter user 'root'@'%' identified with mysql_native_password by'用户密码'; alter user 'root'@'localhost' identified with mysql_native_password by '用户密码';
-
刷新权限 FLUSH PRIVILEGES;
其他: 1. 创建用户 create user 'username'@'host' identified by 'password'
- 为用户授权
grant all privileges on *.* to 'username'@'%' with grant option;
- 删除用户 DROP USER 'username'@'localhost';
sh脚本
mysql -u root -p chenhaifeng -e "CREATE USER 'chf'@'%' IDENTIFIED BY 'chenhaifeng';"
mysql -u root -p chenhaifeng -e "grant all privileges on *.* to 'chf'@'%' with grant option;"
mysql -u root -p chenhaifeng -e "alter user 'chf'@'%' identified with mysql_native_password by'chenhaifeng';"
mysql -u root -p chenhaifeng -e "FLUSH PRIVILEGES;
主数据库
创建用户给slave数据库连接
从数据库
连接主数据库
change master to master_host='master', master_user='root', master_password='chenhaifeng', master_port=3306, master_log_file='mysql-bin.000003', master_log_pos=911, master_connect_retry=30;
SHOW VARIABLES LIKE 'server_id';查看主机id必须要与主数据库不同
start slave; 启动
stop slave; 暂停
show slave status \G; 查看状态