Heim  >  Artikel  >  Datenbank  >  MySQL授权(让从服务器用户可以登录到主服务器)_MySQL

MySQL授权(让从服务器用户可以登录到主服务器)_MySQL

WBOY
WBOYOriginal
2016-06-01 13:32:51970Durchsuche

bitsCN.com

  1、查看用户授权表

select user,host,password from mysql.user;

  2、给用户设置密码

update mysql.user set password=PASSWORD('root') where user='root';flush privileges;

  3、登录MySQL

[root@h2 ~]# mysql -uroot -proot

  4、在从服务器(192.168.0.130)上登录到主服务器(192.168.0.129)

[root@h2 ~]# mysql -uroot -proot -h192.168.0.129ERROR 1045 (28000): Access denied for user 'root'@'h2' (using password: YES)

    可以看到现在无法登录。

  5、在主服务器上给从服务器上的root用户授权,允许从服务器上的root用户访问主服务器

mysql> grant all on *.* to root@192.168.0.130 identified by "root";

    允许192.168.0.130(从服务器)上的root用户访问主服务器,密码是root

  6、查看权限表

mysql> select user,host,password from mysql.user;+--------+---------------+-------------------------------------------+| user   | host          | password                                  |+--------+---------------+-------------------------------------------+| root   | localhost     | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B || root   | h1            |                                           || root   | 127.0.0.1     |                                           ||        | localhost     |                                           ||        | h1            |                                           || hive   | %             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || hive   | localhost     | *4DF1D66463C18D44E3B001A8FB1BBFBEA13E27FC || myhive | localhost     | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || root   | 192.168.0.130 | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |+--------+---------------+-------------------------------------------+9 rows in set (0.00 sec)

    可以看到192.168.0.130主机上的root用户已被授权

  7、现在再次在从服务器上登录主服务器就可以了

[root@h2 ~]# mysql -uroot -proot -h192.168.0.129

 

 

bitsCN.com
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn