mysql默认不允许在localhost
以外的计算机连接,但我们可以设置一下,首先本地登录mysql,执行grant
命令
grant all privileges on *.* to 'usernamexxx'@'%' identified by 'newpasswordxxx' with grant option;
他的语法格式为
grant 权限... on 数据库名.表名 ‘用户名’@‘主机地址’ identified by '密码' ;
all privileges
代表所有权限,包括:select、insert、update、delete、create、drop、index、alter、grant、references、reload、shutdown、process、file
with grant option
代表管理员将权限给了它,它又将权限给了别人,那么当管理员收回某个人权限的时候,所有人的权限都被收回。如果不想全都收回,请使用 with admin option
输入的密码要包含数字,大小写的字母,特殊字符,如果不想输入那么复杂的密码,可以执行下面命令后再设置密码
set global validate_password_policy=0;
接下来我们就可以远程登录mysql了
mysql -h 域名或者IP -u 用户名 -p 数据库名称
网友评论