saveAsDataSource - Save MySQL native interface data source - MATLAB (original) (raw)
Main Content
Save MySQL native interface data source
Since R2020b
Syntax
Description
Examples
Create MySQL Native Interface Data Source
Create, configure, test, and save a MySQL® native interface data source for a MySQL database.
Create a MySQL native interface data source for a MySQL native interface database connection.
vendor = "MySQL"; opts = databaseConnectionOptions("native",vendor)
opts = SQLConnectionOptions with properties:
DataSourceName: ""
Vendor: "MySQL"
DatabaseName: ""
Server: "localhost"
PortNumber: 3306
opts
is an SQLConnectionOptions
object with these properties:
DataSourceName
— Name of the data sourceVendor
— Database vendor nameDatabaseName
— Name of the databaseServer
— Name of the database serverPortNumber
— Port number
Configure the data source by setting the database connection options for the data source MySQLDataSource
, database name toystore_doc
, database server dbtb01
, and port number 3306
.
opts = setoptions(opts, ... 'DataSourceName',"MySQLDataSource", ... 'DatabaseName',"toystore_doc",'Server',"dbtb01", ... 'PortNumber',3306)
opts = SQLConnectionOptions with properties:
DataSourceName: "MySQLDataSource"
Vendor: "MySQL"
DatabaseName: "toystore_doc"
Server: "dbtb01"
PortNumber: 3306
The setoptions
function sets the DataSourceName
, DatabaseName
, Server
, and PortNumber
properties in the SQLConnectionOptions
object.
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 configured data source.
You can connect to the new data source using the mysql function or the Database Explorer app.
Input Arguments
opts
— Database connection options
SQLConnectionOptions
object
Database connection options, specified as an SQLConnectionOptions object.
Version History
Introduced in R2020b
See Also
Objects
Functions
- databaseConnectionOptions | mysql | reset | rmoptions | setoptions | testConnection | deleteDataSource