mysql 数据库授权-开放3306端口-允许远程用户登录-本机用户

通常本机的数据库只允许本地用户登录,此时想要远程用户可登录,步骤:

Linux系统下

首先确定3306端口是对外开放的。

1、netstat  -an|grep 3306

2、打开MySQL配置文件 vi /etc/mysql/mysql.conf.d/mysqld.cnf,将bind-address = 127.0.0.1注销

3、重启ubuntu,再次查看端口是否打开 :netstat -an | grep 3306

4、进入MySQL 进行授权:sudo mysql -u root -p

5、将root用户授权给所有连接: grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx';

6、让权限立即生效:flush privileges;​
到此所以操作完成,可以在任何主机连接此mysql数据库服务器了。

记得要重启mysql

eg:/etc/init.d/mysql restart

具体步骤看:https://www.cnblogs.com/austinspark-jessylu/p/6899279.html

 

 

1、用root用户登录数据库:mysql -uroot -p;

2、成功登录root用户后,输入:

grant all priviliges on 数据库名.*  to 数据库登录用户名@IP indetified by '数据库登录密码' with grant option;

例子:允许远程以root身份登录并全部授权:grant all privileges on *.* to root@'%' identified by '123' with grant option;

3、输入:flush privileges;

复制:

mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’;

权限1,权限2,…权限n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限。
当权限1,权限2,…权限n被all privileges或者all代替,表示赋予用户全部权限。
当数据库名称.表名称被*.*代替,表示赋予用户操作服务器上所有数据库所有表的权限。
用户地址可以是localhost,也可以是ip地址、机器名字、域名。也可以用’%'表示从任何地址连接。
‘连接口令’不能为空,否则创建失败。

 

mysql>grant select,insert,update,delete,create,drop on vtdc.employee to [email protected] identified by ‘123′;
给来自10.163.225.87的用户joe分配可对数据库vtdc的employee表进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。

mysql>grant all privileges on vtdc.* to [email protected] identified by ‘123′;
给来自10.163.225.87的用户joe分配可对数据库vtdc所有表进行所有操作的权限,并设定口令为123。

mysql>grant all privileges on *.* to [email protected] identified by ‘123′;
给来自10.163.225.87的用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。

mysql>grant all privileges on *.* to joe@localhost identified by ‘123′;
给本机用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章