Is there any way to connect toad for mysql without using database toolbox?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
connecting the database without using database toolbox
채택된 답변
Walter Roberson
2017년 10월 19일
Yes.
If you are using MS Windows then you can use activexserver() to connect with a database program.
If you are not using Windows then you can use loadlibrary() to call into a .so (shared library) such as libsql or libmysql
댓글 수: 17
You probably could use loadlibrary on windows as well but actxserver is probably easier.
I've always used actxserver to connect to databases (I don't have the database toolbox and I've never had the need for it).
connection = actxserver('ADODB.Connection');
connection.provider = '...'; %correct provider for your database. No idea what that is for mysql
connection.Open(yourdatabase);
recordset = connection.Execute('SELECT * FROM SomeTable');
@ Walter Roberson Thanks for your answer. I think the function ''actxserver'' is a function used to create the server. Is there any function to access/connect the existing database server especially for TOAD ? Or could you elaborate about this function with sample syntex?
@Guilaume Thanks for your input. Is the code ADO is a generic function?
actxserver is the matlab function to talk to any kind of activeX/COM provider. One of such provider written by microsoft is ADO (Activex Data Object). It is (one of) the APIs provided on Windows to communicate with any database. Full documentation of the API.
actxserver has nothing to do with database server. It can be used to talk with Excel, Word, database servers, and many other program. In my example, it is used to start the ADO library.
To connect with a mysql database, you probably have to use the ODBC provider (see Appendix A) which is the default. You then use the various ADO methods to manipulate your database.
I'm not sure what you're asking about TOAD. As far as I know it is a set of tools to manage your database which is irrelevant for talking to the database from other programs.
@Guilaume thanks for your kind support. I am getting * No public field database exists for class COM.ADODB_Connection* error when I am opening my database by using your command.
Looks like you wrote something like
connection.database = '...'
which is not what I wrote in my example and is not the way to specify the database.
I'm afraid you're going to have to read the documentation for ADODB (which I've linked to twice) and the documentation for whichever ODBC driver you use (e.g. mysql odbc driver) to figure out exactly how to connect to your database. From the above two, it looks like
connection = actxserver('ADODB.Connection');
connection.Open('DRIVER={MySQL ODBC 3.51 Driver};SERVER=LOCALHOST;DATABASE=yourdatabase;UID=username;PWD=password');
or something like that. See the mysql doc for an example of using ADO from VB, which is not much different than using it from matlab.
Sandeep Kumar Radha Krishnan
2017년 10월 23일
편집: Walter Roberson
2017년 10월 23일
Hello, I am getting this following error when it trying to connect the database.
Error using COM.ADODB_Connection/Open
Invoke Error, Dispatch Exception:
Source: Microsoft OLE DB Provider for SQL Server
Description: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not
exist or access denied.
How to find the provider for the mysql-database?
No.. but I am having TOAD for MySQL..
It appears to me that TOAD for MySQL is a package to manage MySQL databases, but that it is not the MySQL server itself. I think you still need to install the MySQL server.
If the MySQL server is installed, how the matlab script will communicate with the database especially after this syntax * 'connection.Open()'*? Can you explain with screenshot?
I cannot show a screenshot. I normally run on a Mac, which cannot use ActiveX from MATLAB. I could start up a Windows Virtual Machine, but I do not have the appropriate Microsoft products to test this -- Microsoft's licensing policies for Virtual Machines is not fun, and I have confirmed with Microsoft and an authorized Microsoft license partner that I would have to pay over $US4000 per year to access the products through my virtual machines -- which is better than the Microsoft site would suggest, as pricing through Microsoft says I would have to pay over $US11000 for two years.
With MySQL Server installed, you should no longer get the message
"SQL Server does not exist or access denied."
How to find out the provider name for MySQL? I was using * SQLOLEDB* and which will be provider for MicrosoftSQL server. Is SQLOLEDB will be same for both MySQL and MSSQL?
You're going to have to put some effort here and read the docs I've linked. If you're not willing to, you're better off buying the database toolbox.
I've already told you that the provider is the OLE DB provider for ODBC. As I said it's the default, meaning you don't even have to specify it.
To connect to a mysql database you obviously need mysql running and the mysql odbc driver I've linked to previously properly installed.
Then as I've said, in matlab:
connection = actxserver('ADODB.Connection');
connection.Open('DRIVER={MySQL ODBC 3.51 Driver};SERVER=LOCALHOST;DATABASE=yourdatabase;UID=username;PWD=password');
The following is a translation of the beginning of the VB example that I've also previously linked to
%connect to MySQL server using Connector/ODBC
conn = actxserver('ADODB.Connection');
conn.ConnectionString = 'DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;UID=venu;PWD=venu; OPTION=3';
conn.Open;
%create table
conn.Execute('DROP TABLE IF EXISTS my_ado');
conn.Execute('CREATE TABLE my_ado(id int not null primary key, name varchar(20), txt text, dt date, tm time, ts timestamp)');
%direct insert
conn.Execute('INSERT INTO my_ado(id,name,txt) values(1,100,''venu'')');
conn.Execute('INSERT INTO my_ado(id,name,txt) values(2,200,''MySQL'')');
conn.Execute "INSERT INTO my_ado(id,name,txt) values(3,300,''Delete'')');
rs = actxserver('ADODB.Recordset');
rs.CursorLocation = 'adUseServer';
%fetch the initial table ..
rs.Open('SELECT * FROM my_ado', conn);
fprintf('rs.RecordCount: %d\n', rs.RecordCount);
rs.MoveFirst;
fprintf([repmat('-', 1, 50), ' Initial my_ado Result Set ', repmat('-', 1, 50), '\n']);
for flditer = 1:rs.Fields.Count
fld = rs.Fields.Item(flditer);
fprintf('%s\t', fld.Name);
end
fprintf('\n');
while ~rs.EOF
for flditer = 1:rs.Fields.Count
fld = rs.Fields.Item(flditer);
fprintf('%s\t', fld.Value);
end
rs.MoveNext;
fprintf('\n');
end
rs.Close;
Mistakes may have been made in the above. It's completely untested. I don't have mysql installed.
Thanks, Guillaume.
Thank you for your kind supports.
GREAT! You saved me a couple days' figuring out.
My slightly polished version of your Matlab code:
% See: Is there any way to connect to mysql without using database toolbox?
% https://www.mathworks.com/matlabcentral/answers/362076-is-there-any-way-to-connect-toad-for-mysql-without-using-database-toolbox
driver = '{MySQL ODBC 8.0 ANSI Driver}';
server = 'localhost';
dbName = 'test';
user = 'venu';
passwd = 'venu';
% Connect to MySQL server using Connector/ODBC
conn = actxserver('ADODB.Connection');
conn.ConnectionString ...
= [ 'DRIVER=' driver '; ' ...
'SERVER=' server '; ' ...
'DATABASE=' dbName '; ' ...
'UID=' user '; ' ...
'PWD=' passwd '; ' ...
'OPTION=3' ];
fprintf('ConnectionString: %s\n', conn.ConnectionString);
conn.Open;
% Create table
conn.Execute('DROP TABLE IF EXISTS my_ado');
conn.Execute('CREATE TABLE my_ado(id int not null primary key, name varchar(20), txt text, dt date, tm time, ts timestamp)');
% Direct insert
conn.Execute('INSERT INTO my_ado(id, name, txt) values(1, 100, ''venu'')');
conn.Execute('INSERT INTO my_ado(id, name, txt) values(2, 200, ''MySQL'')');
conn.Execute('INSERT INTO my_ado(id, name, txt) values(3, 300, ''Delete'')');
rs = actxserver('ADODB.Recordset');
rs.CursorLocation = 'adUseServer';
% Fetch the initial table
query = 'SELECT * FROM my_ado;';
fprintf('Query: %s\n', query);
rs.Open(query, conn);
fprintf('rs.RecordCount: %d\n', rs.RecordCount);
rs.MoveFirst;
fprintf(['\n', repmat('-', 1, 10), ' Initial my_ado Result Set ', repmat('-', 1, 10), '\n']);
for flditer = 0 : rs.Fields.Count - 1
fld = rs.Fields.Item(flditer);
fprintf('%s\t', fld.Name);
end
fprintf('\n');
while ~rs.EOF
flditer = 0;
fld = rs.Fields.Item(flditer);
fprintf('%2d\t', fld.Value);
for flditer = 1 : rs.Fields.Count - 1
fld = rs.Fields.Item(flditer);
fprintf('%s\t', fld.Value);
end
rs.MoveNext;
fprintf('\n');
end
rs.Close;
conn.Close;
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
참고 항목
2017년 10월 19일
2018년 12월 31일
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)
