阿里云mysql远程访问权限_MySQL数据库远程访问权限如何打开(两种方法)

MySQL数据库远程访问权限如何打开(两种方法)

下载GPL版本安装

MySQL Community Edition(GPL)

在我们使用mysql数据库时,有时我们的程序与数据库不在同一机器上,这时我们需要远程访问数据库。缺省状态下,mysql的用户没有远程访问的权限。

下面介绍两种方法,解决这一问题。

1、改表法

可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

mysql -u root -p

mysql>use mysql;

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;

2、授权法

在安装mysql的机器上运行:

1、d:\mysql\bin\>mysql -h localhost -u root

//这样应该可以进入MySQL服务器

2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION

//赋予任何主机访问数据的权限

例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WI

TH GRANT OPTION;

如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3'IDENTIFIED BY

'mypassword' WITH GRANT OPTION;

3、mysql>FLUSH PRIVILEGES

//修改生效

4、mysql>EXIT

退出MySQL服务器,这样就可以在其它任何的主机上以root身份登录

以上所述是小编给大家介绍的MySQL数据库远程访问的权限如何打开,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

您可能感兴趣的文章:

一、

mysqladmin: connect to server at 'localhost' failederror: 'Access denied for user 'root'@'localhost' (using password: YES)'无法修改密码用 service mysqld stopmysqld_safe --skip-grant-tables &输入mysql-uroot -p 回车进入>use mysql;> update user set password=PASSWORD("newpass")where user="root"; 更改密码为 newpassord> flush privileges; 更新权限> quit 退出

service mysqld restartmysql -uroot -p新密码进入

===========================================================

二,忘记本地root的登录密码

解决过程:

1、编辑/etc/my.cnf

在[mysqld] 配置部分添加一行

skip-grant-tables

2、保存后重启mysql

[root@localhost etc]# service mysqld restartShutting down MySQL.                                       [  OK  ]Starting MySQL.                                                   [  OK  ]3、登录数据库重新设置root密码

[root@localhost ~]# mysql -uroot -p mysqlEnter password:

直接回车进入

Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.1.47-log Source distributionCopyright (c) 2000, 2010,Oracleand/or its affiliates. All rights reserved.This software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL v2 licenseType 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || test               |+--------------------+3 rows in set (0.00 sec)执行下列语句mysql> update user set password=password("mysql") where user='root';Query OK, 4 rows affected (0.00 sec)Rows matched: 4  Changed: 4  Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

4、删除/etc/my.cnf文件中添加的“skip-grant-tables”行,重启mysql;

用新设的密码就能正常登录了;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值