Main Content

reset

Reset MySQL native interface connection options to defaults

Since R2020b

Description

opts = reset(opts) resets all connection options to their default values for all properties of the SQLConnectionOptions object. The reset function also removes any additional driver-specific properties from the SQLConnectionOptions object.

example

Examples

collapse all

Create, configure, and test a MySQL® native interface data source for a MySQL database. Reset the database connection options to their default values. Then configure, test, and save the data source with different database connection options.

Create a MySQL native interface data source for a MySQL 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 source

  • Vendor — Database vendor name

  • DatabaseName — Name of the database

  • Server — Name of the database server

  • PortNumber — 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)
status = logical
   1

Reset the database connection options to their default values.

opts = reset(opts)
opts = 
  SQLConnectionOptions with properties:

              DataSourceName: ""
                      Vendor: "MySQL"

                DatabaseName: ""
                      Server: "localhost"
                  PortNumber: 3306

Configure the data source again by setting the database connection options for the data source MySQLDataSource, database name toystore_doc, database server dbtb01, and port number 3306. Also, set a driver-specific connection option to specify a timeout value for establishing the database connection.

opts = setoptions(opts, ...
    "DataSourceName","MySQLDataSource", ...
    "DatabaseName","toystore_doc", ...
    "Server","dbtb01","PortNumber",3306, ...
    "OPT_CONNECT_TIMEOUT",20)
opts = 
  SQLConnectionOptions with properties:

              DataSourceName: "MySQLDataSource"
                      Vendor: "MySQL"

                DatabaseName: "toystore_doc"
                      Server: "dbtb01"
                  PortNumber: 3306

	Additional Connection Options:

         OPT_CONNECT_TIMEOUT: 20

The setoptions function sets the DataSourceName, DatabaseName, Server, and PortNumber properties in the SQLConnectionOptions object. The driver-specific connection option appears below the other connection options.

Test the database connection again.

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

Save the configured data source.

saveAsDataSource(opts)

Input Arguments

collapse all

Database connection options, specified as an SQLConnectionOptions object.

Output Arguments

collapse all

Database connection options, returned as an SQLConnectionOptions object.

Version History

Introduced in R2020b