setoptions
Set MySQL native interface connection options
Description
opts = setoptions(opts,Option1,OptionValue1,...,OptionN,OptionValueN)SQLConnectionOptions object opts.
Examples
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 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
Save the configured data source.
saveAsDataSource(opts)
You can connect to the new data source using the mysql function or the Database Explorer app.
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 = 
  SQLConnectionOptions with properties:
              DataSourceName: "MySQLDataSource"
                      Vendor: "MySQL"
                DatabaseName: "toystore_doc"
                      Server: "dbtb01"
                  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
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)opts = 
  SQLConnectionOptions with properties:
              DataSourceName: "MySQLDataSource"
                      Vendor: "MySQL"
                DatabaseName: "toystore_doc"
                      Server: "dbtb01"
                  PortNumber: 3306
	Additional Connection Options:
         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)
status = logical
   1
Save the updated data source.
saveAsDataSource(opts)
Input Arguments
Database connection options, specified as an SQLConnectionOptions object.
MySQL native interface connection options, specified as one or more name-value
            pair arguments. Option is a character vector or string scalar that
            specifies the name of a MySQL native interface connection option. OptionValue
            specifies the value of the option. OptionValue can be a character
            vector, string scalar, logical scalar, or numeric scalar. You can specify any
              MySQL native interface connection option that is a property of the SQLConnectionOptions object. You can also set driver-specific connection
            options.
Example: 'DataSourceName',"myDataSource",'Server',"localhost",'PortNumber',3306
            configures a MySQL native interface data source named myDataSource that is
            located on the local server with the port number 3306.
Output Arguments
Database connection options, returned as an SQLConnectionOptions object.
Version History
Introduced in R2020b
See Also
Objects
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)