搜索
查看: 1139|回复: 0

ubuntu中mysql允许远程连接

[复制链接]

134

主题

2

回帖

528

积分

高级会员

积分
528
发表于 2014-9-13 11:51:59 | 显示全部楼层 |阅读模式

摘要:一般mysql默认安装出于安全考虑、一般只会让主机连接到mysql、而其他的机器通过远程的方式是连接不上mysql的。这样想在别的机器上远程操作主机的mysql就会denied、当然备份也会被拒绝。记录一下如何解决mysql支持远程。

一:简介

环境依然是前面的环境、可以在其他机器上测试一下是否能远程连接本主机的mysql。我主机的IP是192.168.26.200、mysql用户是root、密码是password、键入如下命令、并输入密码:

mysql–h192.168.26.200 –uroot –p

会提示:

ERROR 2003(HY000): Can't connect to MySQL server on '192.168.26.200' (111)

问题就是我们并没有开启主机、也就是192.168.26.200上的mysql的允许别人远程的配置。

二:解决过程2.1 查看主机上mysql允许连接的机器IP

a) 登录mysql、输入命令:

                mysql  –uroot  –p

b) 输入密码:

                password

c) mysql的相关权限都在mysql这个自带的database内、查看user表的指定字段

                select user,password , host from user where user = 'root';                #会显示如下                +------+-------------------------------------------+-----------+                | user |password                                  | host      |                +------+-------------------------------------------+-----------+                | root |*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | localhost |                +------+-------------------------------------------+-----------+                说明root用户登录下的mysql只允许localhost连接。2.2 实现所有IP可以连接root用户的mysql。

a) 修改root用户下的mysql、即可以指定某些IP能够连接、也可以指定所有的IP可以连接、这里指定的是全部

b) 在上面的查看权限界面执行如下语句:

                grant allprivileges on *.* to 'root'@'%' identified by 'password';                flushprivileges;

如果我们想指定IP连接、那么可以将上面的%换成我们指定的IP、比如指定192.168.30.253可以连接

                grant allprivileges on *.* to 'root'@'192.168.30.253' identified by 'password';                flushprivileges;

修改mysql的配置文件 my.cnf中

                vim /etc/mysql/my.cnf                bind-address = 127.0.0.1                将 bind-address =127.0.0.1 这一行注释掉, 即修改为:                 #bind-address = 127.0.0.12.3 测试

使用其他机器远程登录试试:

                mysql -h192.168.26.200 -uroot –ppassword                #显示如下信息                Welcome to the MySQL monitor.  Commands end with ; or \g.                Your MySQL connection id is 413                Server version: 5.5.35-0ubuntu0.12.04.2(Ubuntu)                 Copyright (c) 2000, 2011, Oracle and/or itsaffiliates. All rights reserved.                 Oracle is a registered trademark of OracleCorporation and/or its                affiliates. Other names may be trademarksof their respective                owners.                 Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.                 mysql>                 则登录成功三: 补充3.1 在window下修改mysql编码:

修改mysql安装目录下的配置文件my.ini。将其中的latin1修改成utf8

3.2window下命令窗口启动、停止mysql服务

停止:

                       net stop mysql

启动:

                       net start mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

 
 
大数据行业交流
大数据行业交流
大数据求职招聘
大数据求职招聘
站长电话:
15010106923
微信联系:
hb-0310
站长邮箱:
ab12-120@163.com
大数据中国微信

QQ   

版权所有: Discuz! © 2001-2013 大数据.

GMT+8, 2024-4-29 08:35 , Processed in 0.050400 second(s), 24 queries .

快速回复 返回顶部 返回列表