sqlread error, in Matlab 2018
Afficher commentaires plus anciens
Error using database.odbc.connection/sqlread (line 174) ODBC Driver Error: [MySQL][ODBC 8.0(a) Driver][mysqld-5.6.38]No database selected
What Can I do?
Réponses (1)
Mark Cafaro
le 14 Mai 2018
This error will occur if DefaultCatalog is null:
>> conn = database('localmysql', 'root', 'pass');
>> conn.DefaultCatalog
ans =
'null'
>> sqlread(conn, 'mytable')
Error using database.odbc.connection/sqlread (line 174)
ODBC Driver Error: [MySQL][ODBC 5.3(a) Driver][mysqld-5.7.20-log]No database selected
You either need to set the default database for the data source in ODBC Data Source Administrator, as follows:
- Open ODBC Data Source Administrator as described at https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/open-the-odbc-data-source-administrator?view=sql-server-2017
- Double-click on the Data Source you are using in the Data Sources table.
- Use the dropdown next to the Database label to select a valid default database.
- Click OK to save the changes.
Or, you need to use the SQL USE statement to switch to a valid database before executing sqlread, as shown:
>> conn.Catalogs
ans =
1×3 cell array
{'information_schema'} {'mysql'} {'performance_schema'}
>> exec(conn, 'USE mysql');
>> sqlread(conn, 'user')
ans =
3×45 table
...
Catégories
En savoir plus sur Database Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!