Can I connect to cloud sql from google cloud platform (Mysql)

8 次查看(过去 30 天)
I am a biginner about database.
just have some experience using mysql for a web
I am struggling to connect Cloud sql from Google Cloud Platform using database toolbox
I cannot understand how "JDBCDriverLocation" work
I installed mysql on my computer due to "JDBCDriverLocation", does't mean to use database installed on my computer
the code is below.
opts = configureJDBCDataSource("Vendor","MySQL");
opts = setConnectionOptions(opts,"DataSourceName","MySQL","Server","xxx.xx.xxx.xxx", ...
"PortNumber",3306,"JDBCDriverLocation","C:\Program Files (x86)\MySQL\Connector J 8.0\mysql-connector-java-8.0.20.jar");
[status msg] = testConnection(opts,username,password);
% status = 0
% msg = JDBC Driver Error: Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago.
% The driver has not received any packets from the server.
is it possible to connect to database on cloud couputing service like RDS on AWS or Cloud sql on GCP?
Please help if anyone have advice for me.

回答(1 个)

Piyush Kumar
Piyush Kumar 2024-10-24,6:07
Connecting to AWS RDS from MySQL Workbench and MATLAB Database Explorer
You can easily connect to databases hosted on cloud services like AWS or GCP using tools such as MySQL Workbench or the Database Explorer in MATLAB. Below are the steps specifically for AWS RDS:
Step 1: Create RDS on AWS
1. Create an RDS Instance:
  • Ensure that the instance is publicly accessible by selecting the appropriate radio button during setup.
  • Take note of the username and password you choose during this process.
2. Retrieve Connection Details:
  • Once the RDS instance is created, navigate to the "Connectivity and Security" tab.
  • Copy the endpoint and port number.
3. Configure Security:
  • To make the instance publicly accessible, add an inbound rule in the VPC security group associated with your RDS instance.
  • You can configure this rule to accept all traffic from any IPv4 address or customize it according to your requirements.
Step 2: Connect Using MySQL Workbench
1. Open MySQL Workbench:
  • Set up a new connection.
  • Enter the copied endpoint in the "Hostname" field and the port number in the "Port" field.
  • Input the username and password you noted earlier.
2. Test and Save Connection:
  • Test the connection to ensure everything is set up correctly.
  • Save the connection details for future use.
3. Access the Database:
  • Log in to the instance and create database instances and tables as needed.
Step 3: Connect Using MATLAB Database Explorer
1. Configure Data Source:
  • Click on "Configure Data Source" and then "Configure JDBC Data Source."
  • Select the JDBC driver file you have downloaded and added to the MATLAB search path. The file path will typically look something like this - "C:\DRIVERS\mysql-connector-j-9.1.0\mysql-connector-j-9.1.0.jar".
2. Enter Connection Details:
  • Enter the endpoint in the "Server" field and the port number in the "Port Number" field.
3. Test and Save Connection:
  • Test the connection to verify the setup.
  • Save the configuration for future use.
4. Access the Database:
  • Connect to the database instance to view tables and data within MATLAB.
Additional Information: JDBC Driver
  • The Database Toolbox in MATLAB connects to any relational database that is ODBC-compliant or JDBC-compliant using ANSI SQL.
  • To connect using the Database Toolbox, ensure that the database-specific ODBC or JDBC driver is installed on your computer.
  • You can download the appropriate driver depending on your database engine by checking this link.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by