一:windows环境 1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysq
一:windows环境
1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 mysql 数据库里的 user 表里的 host 项,从localhost改称%
mysql -u root -pvmwaremysql>use mysql;mysql>update user set host = '%' where user = 'root';mysql>select host, user from user;
2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
grant all privileges on *.* to 'myuser'@'%' identified by 'mypassword' with grant option;
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码
grant all privileges on *.* to 'myuser'@'192.168.1.3' identified by 'mypassword' with grant option;
我 的mysql.user里root用户的host果然是localhost,先用改表法给localhost改成“%”,还是不行,仍然报1130的错 误,,又按“从任何主机连接到mysql服务器”方法授权,还是报一样的错,最后给自己的ip授权之后,终于登录上了。。。。
乎乎。。。
mysql的error 1045 在上面情况后如再出现客户段1045可在服务器执行如下
update user set password=password('123456') where user='myuser';
flush privileges;//用户付完权限后对数据进行刷新时用!要不mysql数据库识别不了
例如:(必须参考以上再看下面的例子)
grant all on *.* to admin@'%' identified by 'admin' with grant option;
mysql 192.168.50.85 admin admin ;
grant all on *.* to admin@'localhost' identified by 'admin' with grant option;
grant all privileges on *.* to 'myuser'@'%' identified by '123456' with grant option;
grant all privileges on *.* to 'myuser'@'192.168.50.85' identified by '123456' with grant option;
update user set password=password('123456') where user='myuser';
flush privileges;
mysql默认是没有开启远程控制的,必须添加远程访问的用户。
mysql默认是没有开启远程控制的,必须添加远程访问的用户。 g&00 x$ y
0ve }0(fq
如果是安装版的话,从mysql提供的控制台进入。 1s+
用root用户登陆,然后: q k c jgs0
grant all privileges on *.* to 创建的用户名 @% identified by 密码; o! q*)`xuq
flush privileges; * 刷新刚才的内容* )/ z (5 3x
; (q:ly \v
格式:grant 权限 on 数据库名.表名 to 用户@登录主机 identified by 用户密码; .=h j qi[
@ 后面是访问mysql的客户端ip地址(或是 主机名) % 代表任意的客户端,如果填写 localhost 为本地访问(那此用户就不能远程访问该mysql数据库了)。 u
lp 8 z rc
同时也可以为现有的用户设置是否具有远程访问权限。如下: \ch3 x x#
use mysql; o$`> :>n e
update db set host = '%' where user = '用户名'; (如果写成 host=localhost 那此用户就不具有远程访问权限) b gnl: r *
flush privileges; zn 6en;&?
3 pj_2b=
查看结果,执行: $4b 5-u
use mysql; ){[' 66!
select host,user,password from user; j):h\b:j_m
i oz 0 h
+--------------+--------+---------------+ t75 jsdq
| host | user | password | xkl di{ u
+--------------+--------+-----------------+ b*1q
| localhost | | | u 8rzq(f
| % | john | 123456 | r ` al b
| localhost | root | | h fd ze
+--------------+------ --+---------------+ pd7= 8 8
arj~vs +
总结: ? av l`b a
其实mysql默认有两个数据库分别为 mysql 和 test 而mysql用户的信息都放在数据库 mysql 的相关表中 gb: hj /
也可以使用 navicat (推荐)这样的gui工具来管理用户。 hud?}u bb5
update user set host='%' where host='localhost'
工作中用到web服务器和mysql服务器不在同一台计算机上安装的运用。需要通过mysql的远程账户访问mysql。
先上语法:
grant [权限] on [数据库名].[表命] to ['用户命']@['web服务器的ip地址'] identified by ['密码'];
实例:
grant all on lportal.* to 'root'@'192.168.1.21 identified by 'root';
grant select,update,insert,delete on lportal.* to 'root'@'192.168.1.21 identified by 'root';