`
xiaoane
  • 浏览: 1678 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

转Mysql远程链接

阅读更多
1、进入mysql,创建一个新用户root,密码为root:

   格式:grant 权限 on 数据库名.表名 to 用户@登录主机 identified by "用户密码";
           grant select,update,insert,delete on *.* to root@192.168.1.12 identified by "root";

   原先数据表结构

    mysql> use mysql;
    Database changed
    mysql> select host,user,password from user;
    +-----------+------+-------------------------------------------+
    | host      | user | password                                  |
    +-----------+------+-------------------------------------------+
    | localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
    +-----------+------+-------------------------------------------+

   执行上述语句后结果

    mysql> use mysql;
    Database changed
    mysql> select host,user,password from user;
    +--------------+------+-------------------------------------------+
    | host         | user | password                                  |
    +--------------+------+-------------------------------------------+
    | localhost    | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
    | 192.168.1.12 | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
    +--------------+------+-------------------------------------------+
    2 rows in set (0.00 sec)

the article below is more useful !

How Do I Enable Remote Access To MySQL Database Server?

by Vivek Gite on March 31, 2006 · 103 comments

By default remote access to MySQL database server is disabled for security reasons. However, some time you need to provide remote access to database server from home or a web server.
MySQL Remote Access

You need type the following commands which will allow remote connections.
Step # 1: Login Using SSH (if server is outside your data center)

First, login over ssh to remote MySQL database server:

ssh user@mysql.nixcraft.i

Step # 2: Edit my.cnf File

Once connected you need to edit the MySQL server configuration file my.cnf using a text editor such as vi.

    * If you are using Debian Linux file is located at /etc/mysql/my.cnf location
    * If you are using Red Hat Linux/Fedora/Centos Linux file is located at /etc/my.cnf location
    * If you are using FreeBSD you need to create a file /var/db/mysql/my.cnf

Edit /etc/my.cnf, run:
# vi /etc/my.cnf
Step # 3: Once file opened, locate line that read as follows

[mysqld]

Make sure line skip-networking is commented (or remove line) and add following line

bind-address=YOUR-SERVER-IP

For example, if your MySQL server IP is 65.55.55.2 then entire block should be look like as follows:

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
language        = /usr/share/mysql/English
bind-address    = 65.55.55.2
# skip-networking
....
..
....

Where,

    * bind-address : IP address to bind to.
    * skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should be removed from my.cnf or put it in comment state.

Step# 4 Save and Close the file

Restart the mysql server, enter:
# /etc/init.d/mysql restart
Step # 5 Grant access to remote IP address

Connect to mysql server:
$ mysql -u root -p mysql
Grant access to a new database

If you want to add a new database called foo for user bar and remote IP 202.54.10.20 then you need to type the following commands at mysql> prompt:mysql> CREATE DATABASE foo;
mysql> GRANT ALL ON foo.* TO bar@'202.54.10.20' IDENTIFIED BY 'PASSWORD';
How Do I Grant Access To An Existing Database?

Let us assume that you are always making connection from remote IP called 202.54.10.20 for database called webdb for user webadmin, To grant access to this IP address type the following command At mysql> prompt for existing database, enter:
mysql> update db set Host='202.54.10.20' where Db='webdb';
mysql> update user set Host='202.54.10.20' where user='webadmin';
Step # 5: Logout of MySQL

Type exit command to logout mysql:mysql> exit
Step # 6: Open port 3306

You need to open TCP port 3306 using iptables or BSD pf firewall.
A sample iptables rule to open Linux iptables firewall

/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT

OR only allow remote connection from your web server located at 10.5.1.3:

/sbin/iptables -A INPUT -i eth0 -s 10.5.1.3 -p tcp --destination-port 3306 -j ACCEPT

OR only allow remote connection from your lan subnet 192.168.1.0/24:

/sbin/iptables -A INPUT -i eth0 -s 192.168.1.0/24 -p tcp --destination-port 3306 -j ACCEPT

Finally save all rules:
# service iptables save
A sample FreeBSD / OpenBSD pf rule ( /etc/pf.conf)

pass in on $ext_if proto tcp from any to any port 3306

OR allow only access from your web server located at 10.5.1.3:

pass in on $ext_if proto tcp from 10.5.1.3 to any port 3306  flags S/SA synproxy state

Step # 7: Test it

From your remote system or your desktop type the following command:
$ mysql -u webadmin –h 65.55.55.2 –p
Where,

    * -u webadmin: webadmin is MySQL username
    * -h IP or hostname: 65.55.55.2 is MySQL server IP address or hostname (FQDN)
    * -p : Prompt for password

You can also use telnet to connect to port 3306 for testing purpose:
$ telnet 65.55.55.2 3306

我的最终解决办法除了上面英文描述方法外,还有就是在用toad链接mysql时采用ssh方式,而不是tcp方式连接。
分享到:
评论

相关推荐

    MYSQL无法远程连接

    ### MySQL无法远程连接问题解析与解决方案 #### 一、问题背景 MySQL是一种广泛使用的开源关系型数据库管理系统,因其高效稳定而被众多企业和开发者所青睐。然而,在实际部署和使用过程中,有时会遇到无法进行远程...

    牛族MYSQL 远程连接器1.8

    【牛族MYSQL远程连接器1.8】是一款专为MySQL数据库设计的图形化远程连接工具,它使得用户可以通过直观的用户界面与远端MySQL服务器进行交互。这款软件简化了数据库管理,尤其是对于需要频繁跨网络操作数据库的专业...

    MYSQL数据库远程连接

    MYSQL数据库远程连接,例程,需要有亦众的支持库才能编译。

    设置mysql远程连接

    ### 设置MySQL远程连接知识点详解 #### 一、背景与需求 在进行数据库管理与应用开发的过程中,有时我们需要从远程服务器访问MySQL数据库。这通常适用于分布式系统或需要进行远程调试及维护的情况。为了实现这一...

    牛族MYSQL远程连接器1.6

    1 可以无需安装MYSQL数据库,用SuperMysql连接器可以连接远程MYSQL数据库。 2 远程数据库表直接显示在程序的显示框中,无需手工输入指令。 3 程序绑定了三个MYSQL指令。 增加功能: a 远程更改密码时可以自己定义...

    远程用户连接mysql授权

    4. **日志记录**:启用MySQL的日志记录功能,以便于监控远程连接活动和审计。 5. **性能考虑**:大量远程连接可能会对服务器性能造成影响,请合理规划并发连接数量。 #### 五、总结 通过本文介绍的步骤,您可以...

    mysql允许远程连接

    MySQL 远程连接设置 MySQL 是一个广泛使用的关系数据库管理系统,它提供了强大的数据存储和管理功能。但是,默认情况下,MySQL 帐号不允许从远程登录,只能在 localhost 登录。然而,在某些情况下,我们需要从远程...

    mysql远程连接工具

    真正好用的mysql连接工具,内附破解码,真正好用。。

    XAMPP 设置远程连接MYSQL

    设置文件 开通防火墙端口 设置权限 让XAMPP远程连接MYSQL

    mysql开启远程连接权限

    ### MySQL开启远程连接权限 在本篇文章中,我们将详细介绍如何通过命令行的方式,在Windows系统上为MySQL数据库开启远程连接权限。对于需要从不同位置管理数据库的用户来说,这是一个非常实用的功能。下面,我们将...

    mysql远程连接不了

    mysql远程连接不了

    Linux开启mysql远程连接

    ### Linux开启MySQL远程连接详解 #### 一、背景介绍 随着云计算和大数据技术的发展,Linux作为服务器操作系统的优势日益凸显,而MySQL作为一款广泛使用的开源关系型数据库管理系统,在Linux环境下更是得到了广泛...

    MySQL远程连接工具 Navicat for SQL Server

    MySQL远程连接工具 Navicat for SQL Server 解压就可以用

    MySql实现远程连接.txt

    #### 一、MySQL远程连接概述 MySQL 是一款非常流行的开源关系型数据库管理系统,广泛应用于各类网站及软件系统中。为了满足不同场景下的需求,MySQL 支持本地连接和远程连接。其中,远程连接允许用户从其他主机访问...

    通过Navicat for MySQL远程连接的时候报错mysql 1130的解决方法.pdf

    Navicat for MySQL 远程连接错误 1130 解决方法 Navicat for MySQL 是一款功能强大的数据库管理工具,但是在远程连接 MySQL 服务器时,可能会遇到错误 1130,这是因为 MySQL 服务器不允许从远程主机连接。下面我们...

    delphi远程连接MySQL(完美版)

    对于远程连接MySQL,首先确保你的MySQL服务器已经配置为接受远程连接。这通常涉及到修改`my.cnf`配置文件中的`bind-address`项,设置为`0.0.0.0`,然后重启MySQL服务。同时,为了安全,需要在MySQL的用户权限表中,...

    MySQL远程连接丢失问题解决方法(Lost connection to MySQL server)

    远程连接mysql是总是提示: 代码如下:Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0 很明显这是连接初始化阶段就丢失了连接的错误。 google半天大多是说的注释掉...

    CentOS 8 安装 MySql并设置允许远程连接的方法

    总之,这个教程详细介绍了在CentOS 8系统上安装MySQL 5.7的步骤,并指导了如何配置MySQL以接受远程连接。通过遵循这些步骤,你可以确保你的数据库服务不仅能够本地运行,而且还能从任何地方进行访问,这对于远程管理...

    mysql本地可以连接,远程无法连接.txt

    mysql本地可以连接,远程无法连接.txt

Global site tag (gtag.js) - Google Analytics