mysql> use mysql;
Database changed
mysql> grant all privileges on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
查看是否绑定了域名
#c查看my.cnf或者my.ini配置文件,检查是否绑定了域名,并将其注释掉
bind-address =127.0.0.1
授权
任意主机以用户root和密码mypwd连接到mysql服务器
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;
mysql> flush privileges;
IP为192.168.1.102的主机以用户myuser和密码mypwd连接到mysql服务器
mysql> GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.102' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;
mysql> flush privileges;
补充
with grant option的作用
表示是否具有授权的能力
举例:
grant select ,update on bd_corp to testuser1 [with grant option ]
1.如果带了 with grant option
那么用户testuser1可以将select ,update权限传递给其他用户( 如testuser2)
grant select,update on bd_corp to testuser2
2.如果没带with grant option
那么用户testuser1不能给testuser2授权
报错
The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> grant all on cactidb.* to dbuser@'localhost' identified by '123';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
解决方法:
先刷新一下权限表。
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all on cactidb.* to dbuser@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec)