mysql 远程连接数据库的二种方法
来源:互联网 发布:gre作文字数 知乎 编辑:程序博客网 时间:2024/04/30 16:27
一、连接远程数据库:
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:
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>
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>
转载地址:http://blog.csdn.net/freecodetor/article/details/5799550
1 0
- mysql 远程连接数据库的二种方法
- mysql 远程连接数据库的二种方法
- mysql 远程连接数据库的二种方法 .
- mysql 远程连接数据库的二种方法
- mysql 远程连接数据库的二种方法
- mysql 远程连接数据库的二种方法
- mysql 远程连接数据库的二种方法
- mysql 远程连接数据库的二种方法
- mysql 远程连接数据库的二种方法
- mysql 远程连接数据库的二种方法
- mysql数据库开放远程连接的方法
- mysql 远程连接数据库的方法集合
- 远程连接mysql数据库的方法
- ofbiz连接mysql数据库的方法二
- mysql 远程连接数据库的方法以及常用命令(转)
- mysql 远程连接数据库的方法以及常用命令(转)
- 实现远程连接Mysql数据库的简便方法
- 远程连接mysql的方法
- mysql、sqlserver、db2、oracle、hsql数据库获取数据库连接方法及分页函数
- 1, libyuv 编译 for android
- Git-Egit的安装
- AC自动机模板
- ConcurrentHashMap
- mysql 远程连接数据库的二种方法
- 欢迎使用CSDN-markdown编辑器
- 微信支付获取prepay_id以及回调地址
- 我国人口预计 15 年内是会逐渐分散在大中小城市,还是继续向大城市集中?我们应留在大城市发展吗?
- 创业那些年,我们一起走过的坑
- myeclipse安装svn,注销svn账号
- python字符串编码和转换
- 【jzoj4710】【Value】
- Java软件工程师就业思维图(2016年版)