NATAPP配置教程

1、进入NATAPP 登录/注册 进行登录,没有的注册一下,需要实名认证哦,也可以去使用别的内网穿透工具.

登录后进入购买隧道选项卡(有免费的可以领取),然后点击免费隧道

pythonTCP透传 python内网穿透库_远程调用MySQL

2、我们只需要修改一下 隧道协议 即可,修改成TCP,然后点击免费领取

pythonTCP透传 python内网穿透库_远程调用MySQL_02

3、点击我的隧道选项卡,找到TCP隧道点击 配置

pythonTCP透传 python内网穿透库_Pytohn 调用_03

 

4、我们提前复制好口令,一会需要使用,把本地地址修改成【127.0.0.1】,本地端口修改成【3306】,这个端口是MySQL的默认端口,具体根据 my.ini 进行配置,然后点击修改即可保存

pythonTCP透传 python内网穿透库_远程调用MySQL_04

pythonTCP透传 python内网穿透库_数据库_05

 

 

5、点击下载 NATAPP客户端 ,windwos 或 linux 都可使用,方式方法一样

pythonTCP透传 python内网穿透库_Pytohn 调用_06

 

6、我们将下载好的文件解压,然后打开natapp所在文件夹,在地址栏里输入cmd回车,可以看到会打开一个cmd窗口

pythonTCP透传 python内网穿透库_远程调用MySQL_07

 

7、然后我们在cmd窗口内输入【natapp -authtoken=口令】,把你刚刚复制的口令粘贴上,然后回车即可。linux是【./natapp -authtoken=口令】需要先赋权限哦

pythonTCP透传 python内网穿透库_Pytohn 调用_08

pythonTCP透传 python内网穿透库_pythonTCP透传_09

 

8、接下来我们在另一台电脑打开【Navicat for MySQL】,一个MySQL数据库工具

 

pythonTCP透传 python内网穿透库_pythonTCP透传_10

 9、打开连接,点击MySQL 

pythonTCP透传 python内网穿透库_pythonTCP透传_11

 

10、我们 修改一个远程主机IP(内网传统工具natapp 产生的IP)和端口,然后我们填写要连接的数据库用户名称和密码,然后点击确定

pythonTCP透传 python内网穿透库_远程调用MySQL_12

 

pythonTCP透传 python内网穿透库_数据库_13

 

11、然后双击这个服务器,就可以看到已经打开了

pythonTCP透传 python内网穿透库_Pytohn 调用_14

 

使用python 进行调用数据库【新建表】

需要手动修改一下 数据库用户、密码、连接的数据库、端口,运行一下

import pymysql

# 数据库连接信息
conn = pymysql.connect(
       host='server.natappfree.cc',     # 主机IP
       user='root',      #  数据库用户  需改
       passwd='*****',    # 密码  需改
       db='mysql',     # 连接的数据库  需改
       port=43371,     # 端口  需改
       charset="utf8")     # 编码

# 使用cursor 获取操作
cursor = conn.cursor()
# 执行语句
cursor.execute("""
create table NAME_1
(
id int(10) null comment 'user_id',
name varchar(10) null comment 'user_name',
age varchar(10) null comment 'user_old');
""")
# 提交到数据库进行执行
conn.commit()
# 关闭服务
conn.close()
cursor.close()

pythonTCP透传 python内网穿透库_远程调用MySQL_15

 

使用python 进行调用数据库【对表插入数据】

执行语句  【insert into 表对象(栏位,栏位,栏位) value (值,值,值)】,运行一下

import pymysql

# 数据库连接信息
conn = pymysql.connect(
       host='server.natappfree.cc',     # 主机IP
       user='root',      #  数据库用户  需改
       passwd='*****',    # 密码  需改
       db='mysql',     # 连接的数据库  需改
       port=43371,     # 端口  需改
       charset="utf8")     # 编码

# 使用cursor 获取操作
cursor = conn.cursor()
# 执行语句   
cursor.execute("insert into name_1(id,name,age) value (%s,%s,%s)",['001','王先生','24'])
# 提交到数据库进行执行
conn.commit()
# 关闭服务
conn.close()
cursor.close()

pythonTCP透传 python内网穿透库_数据库_16

 

 使用python 进行调用数据库【对表查数据】

【select * from name_1 where age>50】查找 name_1 表内 所有age的值大于50的数据,并打印出全部条目*

import pymysql

# 数据库连接信息
conn = pymysql.connect(
       host='server.natappfree.cc',     # 主机IP
       user='root',      #  数据库用户  需改
       passwd='*****',    # 密码  需改
       db='mysql',     # 连接的数据库  需改
       port=43371,     # 端口  需改
       charset="utf8")     # 编码

# 使用cursor 获取操作
cursor = conn.cursor()
# 执行语句   
cursor.execute("select * from name_1 where age>50")
# 获取所有记录列表(用于查询数据使用)
results = cursor.fetchall()
for a in results:
   print('查询到:',a)
# 提交到数据库进行执行
conn.commit()
# 关闭服务
conn.close()
cursor.close()

 

使用python 进行调用数据库【删除表】

【drop table if exists name_1】 如果name_1存在则删除,运行一下,然后再刷新一下就可以看到已经删除掉了

import pymysql

# 数据库连接信息
conn = pymysql.connect(
       host='server.natappfree.cc',     # 主机IP
       user='root',      #  数据库用户  需改
       passwd='*****',    # 密码  需改
       db='mysql',     # 连接的数据库  需改
       port=43371,     # 端口  需改
       charset="utf8")     # 编码

# 使用cursor 获取操作
cursor = conn.cursor()
# 执行语句   
cursor.execute("drop table if exists name_1")
# 提交到数据库进行执行
conn.commit()
# 关闭服务
conn.close()
cursor.close()

pythonTCP透传 python内网穿透库_NATAPP内网穿透_17