%% Edit Existing MySQL Native Interface Data Source
% Edit an existing MySQL® native interface data source for a MySQL database. Set an additional driver-specific option and save the data source.
%
% Retrieve the existing MySQL data source MySQLDataSource.

datasource = "MySQLDataSource";
opts = databaseConnectionOptions(datasource)

% opts is an SQLConnectionOptions object with these properties:
% DataSourceName — Name of the data source
% Vendor — Database vendor name
% DatabaseName — Name of the database
% Server — Name of the database server
% PortNumber — Port number
%
% Add a driver-specific connection option by using a name-value pair argument. The option specifies a timeout value for establishing the database connection. opts contains a new section of properties for the additional connection option.

opts = setoptions(opts,"OPT_CONNECT_TIMEOUT",20)

%
% Test the database connection with a user name and password. The testConnection function returns the logical 1, which indicates the database connection is successful.

username = "root";
password = "matlab";
status = testConnection(opts,username,password)

%
% Save the updated data source.

saveAsDataSource(opts)

% Copyright 2020 The MathWorks, Inc.