Connecting to MySQL
It is also possible to query existing data on MySQL directly without loading it to PuppyGraph. Here is an demo of the feature.
In the demo, the mysql data source stores people and referral information. To query the data as a graph, we model people as vertices and the referral relationship between people as edges.
Prerequisites
The demo assumes that PuppyGraph has been deployed at localhost
according to the instruction in Launching PuppyGraph from AWS Marketplace or Launching PuppyGraph in Docker.
In this demo, we use the username puppygraph
and password puppygraph123
.
Data Preparation (Optional)
ID | Age | Name |
---|---|---|
v1 | 29 | marko |
v2 | 27 | vadas |
The demo uses people and referral information as shown above.
The following command starts a MySQL container through Docker and writes data to MySQL. We assume that the IP address of the machine running the MySQL container is 172.31.19.123
After waiting for the MySQL container to start, connect through MySQL client。
Now we can create a database and data table, and then write the data to MySQL.
Upload the schema
Now the data are ready in MySQL. We need a PuppyGraph schema before querying it. Let's create a schema file mysql.json
:
Here are some notes on this schema:
A catalog
jdbc_mysql
is added to specify the remote data source in MySQL.Set
type
tomysql
.driverClass
: The class name of the JDBC driver.com.mysql.jdbc.Driver
(MySQL v5.x and earlier)com.mysql.cj.jdbc.Driver
(MySQL v6.x and later)
driverUrl
: Please provide a URL where PuppyGraph can find the MySQL driver. Note the IP address is resolved against the network PuppyGraph container, if you have launched PuppyGraph using Docker in the same host. In this case you might want to use172.17.0.1
orhost.docker.internal
.
The label of the vertices and edges do not have to be the same as the names of corresponding tables in MySQL. There is a
mappedTableSource
field in each of the vertex and edge types specifying the actual schema (graph
) and table (referral
).Additionally, the
mappedTableSource
marks meta columns in the tables. For example, the fieldsfrom
andto
describe which columns in the table form the endpoints of edges.
Now we can upload the schema file mysql.json
to PuppyGraph with the following shell command, assuming that the PuppyGraph is running on localhost
:
Query the data
Connecting to PuppyGraph at http://localhost:8081 and start gremlin console from the "Query" section:
Now we have connected to the Gremlin Console. We can query the graph:
Last updated