连接远程mysql数据库使用下列哪个格式

连接远程mysql数据库使用下列哪个格式,第1张

连接远程mysql数据库使用个格式是mysql-hip地址-u用户名-p用户密码。MySQL是一个关系型数据库管理系统,由瑞典MySQLAB公司开发,属于Oracle旗下产品。MySQL是最流行的关系型数据库管理系统之一,在WEB应用方面,MySQL是最好的RDBMS(RelationalDatabaseManagementSystem,关系数据库管理系统)应用软件之一。

第一:更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称'%'。 \x0d\x0a或者新加条记录,“host” 项为要访问的ip地址,并授权。重启mysql服务。 \x0d\x0a第二:在系统防火墙添加例外端口:3306,并允许例外。 \x0d\x0a\x0d\x0a错误提示: \x0d\x0aERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL server \x0d\x0a的解决方法: \x0d\x0a1。改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%" \x0d\x0a1.mysql -u root -pvmware\x0d\x0amysql>use mysql\x0d\x0amysql>update user set host = '%' where user = 'root'\x0d\x0amysql>select host, user from user \x0d\x0a\x0d\x0a2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。 \x0d\x0a\x0d\x0aGRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION\x0d\x0a如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码 \x0d\x0aGRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION\x0d\x0a\x0d\x0a3.在window自带的防火墙里的例外添加3306端口 \x0d\x0a\x0d\x0a总结: \x0d\x0amysql -u root -p \x0d\x0amysql>use mysql\x0d\x0amysql>select 'host' from user where user='root'\x0d\x0amysql>update user set host = '%' where user ='root'\x0d\x0amysql>flush privileges\x0d\x0amysql>select 'host' from user where user='root'\x0d\x0a第一句是以权限用户root登录 \x0d\x0a第二句:选择mysql库 \x0d\x0a第三句:查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称) \x0d\x0a第四句:修改host值(以通配符%的内容增加主机/IP地址),当然也可以直接增加IP地址 \x0d\x0a第五句:刷新MySQL的系统权限相关表 \x0d\x0a第六句:再重新查看user表时,有修改。。 \x0d\x0a重起mysql服务即可完成。

一、连接远程数据库:

1、显示密码

如:MySQL 连接远程数据库(192.168.5.116),端口“3306”,用户名为“root”,密码“123456”

C:/>mysql -h 192.168.5.116 -P 3306 -u root -p123456

2、隐藏密码

如:MySQL 连接本地数据库,用户名为“root”,

C:/>mysql -h localhost -u root -p

Enter password:

二、配置mysql允许远程链接

默认情况下,mysql帐号不允许从远程登陆,只能在localhost登录。本文提供了二种方法设置mysql可以通过远程主机进行连接。

一、改表法

在localhost登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,将"localhost"改称"%"

例如:

#mysql -u root -p

Enter password:

……

mysql>

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

mysql>select host, user from user

二、授权法

例如: 你想myuser使用mypassword(密码)从任何主机连接到mysql服务器的话。

mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WITH GRANT OPTION

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

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

'mypassword' WITH GRANT OPTION

mysql>FLUSH PRIVILEGES

使修改生效,就可以了

常见问题:

1、在采用法二授权法之后,无法在本地登录mysql(如:#mysql -u root -p -h 192.168.5.116

Enter password:

ERROR 1045 (28000): Access denied for user 'root'@'loadb116' (using password: YES)

上例中loadb116是主机名.

解决方法:

1、这时可以使用:mysql -u root -p 登录,进入到mysql后。

mysql>grant all privileges on *.* to 'root'@'loadb116'

identified by '123456' with grant option

Query OK, 0 rows affected (0.00 sec)

mysql>flush privileges

Query OK, 0 rows affected (0.00 sec)

2、在本地使用ip地址登录

# mysql -u root -p -h 192.168.5.116

Enter password:

Welcome to the MySQL monitor. Commands end with or /g.

Your MySQL connection id is 60

Server version: 5.1.45 MySQL Community Server (GPL)

Type 'help' or '/h' for help. Type '/c' to clear the buffer.

mysql>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5898986.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-07
下一篇 2023-03-07

发表评论

登录后才能评论

评论列表(0条)

保存