sqlread error, in Matlab 2018

8 ビュー (過去 30 日間)
Alex Fernandez
Alex Fernandez 2018 年 5 月 12 日
回答済み: Mark Cafaro 2018 年 5 月 14 日
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?

回答 (1 件)

Mark Cafaro
Mark Cafaro 2018 年 5 月 14 日
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
...

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by