How Can I connect matlab with my sql in other pc

7 views (last 30 days)
i can connect matlab to mysql, but only in localhost. and i will try to connect the matlab to other IP, not only to local IP(127.0.0.1 or localhost).

Answers (1)

Piyush Kumar
Piyush Kumar on 30 Oct 2024 at 8:55
Hi,
To connect MATLAB to a MySQL database on another PC, you’ll need to ensure a few things are set up correctly.
1. Find the ip-address of machine from where you want to connect.
2. In the MySQL server configuration, add the following and restart the mysql server to apply these changes.
% my.cnf file
[mysqld]
bind-address = <ip-address-of-client-machine>
3. Granting Access: Granting access to a user from a remote host.
GRANT ALL PRIVILEGES ON *.* TO 'username'@'client_machine_ip' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
4. Firewall Settings: Ensure that the firewall on the remote PC allows incoming connections on the MySQL port (default is 3306).
5. MATLAB Connection: Use the database function in MATLAB to connect to the remote MySQL server. Replace 'remote_ip' with the IP address of the remote PC:
conn = database('your_database_name', 'username', 'password', 'Vendor', 'MySQL', 'Server', 'remote_ip', 'PortNumber', 3306);

Community Treasure Hunt

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

Start Hunting!