sqlread error, in Matlab 2018

조회 수: 6 (최근 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 CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by