%% Import Data from Database Table Using MySQL Native Interface
% Use a MySQL® native interface database connection to import product data from a database table into MATLAB® using a MySQL database. Then, perform a simple data analysis.
%
% Create a MySQL native interface database connection to a MySQL database. The database contains the table productTable.

datasource = "MySQLNative";
username = "root";
password = "matlab";

conn = mysql(datasource,username,password);

%
% Import data from the database table productTable. The sqlread function returns a MATLAB table that contains the product data.

tablename = "productTable";
data = sqlread(conn,tablename);

% Display the first few rows of product data.

head(data,3)

%
% Close the database connection.

close(conn)

% Copyright 2020 The MathWorks, Inc.