MySQL connector for an external MySQL database queries.
Prerequisites
MySQL server installation.
Configuration settings
I hope you have the mysql server is installed on your computer. To enable property on Presto mysql server, you must "etc / catalog" Create a directory "mysql.properties " file. Issue the following command to create a mysql.properties file.
$ cd etc
$ cd catalog
$ vi mysql.properties
connector.name = mysql
connection-url = jdbc:mysql://localhost:3306
connection-user = root
connection-password = pwd
Save the file and exit the terminal. In the file, you must enter your password in mysql connection-password field.
Create a database in the MySQL server
Open the MySQL server and create a database using the following command.
create database tutorials
You have now created a "tutorials" in the server database. To enable the database type, use the command "use tutorials" in the query window.
Create a table
Let's create a simple table on "tutorials" database.
create table author(auth_id int not null, auth_name varchar(50),topic varchar(100))
Insert Table
After you create a table, use the following query insert three records.
insert into author values(1,'Doug Cutting','Hadoop')
insert into author values(2,’James Gosling','java')
insert into author values(3,'Dennis Ritchie’,'C')
Select the Record
To retrieve all the records, enter the following query.
Inquire
select * from author
result
auth_id auth_name topic
1 Doug Cutting Hadoop
2 James Gosling java
3 Dennis Ritchie C
So far, you've been using MySQL server query data. Let's connect the memory card to the Presto Mysql server.
Presto CLI connection
Enter the following command to connect MySql plug-in on Presto CLI.
./presto --server localhost:8080 --catalog mysql --schema tutorials
You will receive the following response.
presto:tutorials>
Where "tutorials" refers to the mysql server schema.
Lists the schema
To list all the schema mysql, enter the following query in the Presto server.
Inquire
presto:tutorials> show schemas from mysql;
result
Schema
information_schema
performance_schema
sys
tutorials
From the results, we can conclude that the first three are predefined schema, a schema is the last you create yourself.
Listed in the table from Schema
The following query will list "tutorials" all the tables in the schema.
Inquire
presto:tutorials> show tables from mysql.tutorials;
result
Table
author
In this schema we only created one table. If you create more than one table, it will list all the tables.
Description Table
To description field, enter the following query.
Inquire
presto:tutorials> describe mysql.tutorials.author;
result
Column | Type | Comment
---+--+-
auth_id | integer |
auth_name | varchar(50) |
topic | varchar(100) |
Table Column Display
Inquire
presto:tutorials> show columns from mysql.tutorials.author;
result
Column | Type | Comment
---+--+-
auth_id | integer |
auth_name | varchar(50) |
topic | varchar(100) |
Access table records
Mysql table from the get all the records, issue the following query.
Inquire
presto:tutorials> select * from mysql.tutorials.author;
result
auth_id | auth_name | topic
-++
1 | Doug Cutting | Hadoop
2 | James Gosling | java
3 | Dennis Ritchie | C
From this result, you can retrieve mysql server records in the Presto.
Create a table using as a command
Mysql connector does not support creating table query, but you can create a table using as a command.
Inquire
presto:tutorials> create table mysql.tutorials.sample as
select * from mysql.tutorials.author;
result
CREATE TABLE: 3 rows
You can not insert rows directly, because this connector has some limitations. It does not support the following query -
- create
- insert
- Update
- delete
- drop
To view the newly created records in the table, enter the following query.
Inquire
presto:tutorials> select * from mysql.tutorials.sample;
result
auth_id | auth_name | topic
-++
1 | Doug Cutting | Hadoop
2 | James Gosling | java
3 | Dennis Ritchie | C
Original link large column https://www.dazhuanlan.com/2019/07/19/apache-presto%e6%95%99%e7%a8%8b-mysql%e8%bf%9e%e6%8e%a5% e5% 99% a8 /