sqlread error, in Matlab 2018

6 views (last 30 days)
Alex Fernandez
Alex Fernandez on 12 May 2018
Answered: Mark Cafaro on 14 May 2018
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?

Answers (1)

Mark Cafaro
Mark Cafaro on 14 May 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:
  1. 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
  2. Double-click on the Data Source you are using in the Data Sources table.
  3. Use the dropdown next to the Database label to select a valid default database.
  4. 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
...

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!