La connectivité IP publique est plus appropriée lorsque la base de données source est externe à Google Cloudet qu'elle dispose d'une adresse IPv4 et d'un port TCP accessibles en externe. Si la base de données source est hébergée dans un autre VPC dans Google Cloud, le moyen le plus simple de la connecter à l'instance Cloud SQL est d'utiliser l'appairage de VPC.
Si votre base de données source est externe à Google Cloud, ajoutez l'adresse IP sortante (et le port 3306) de la base de données de destination en tant que règle de pare-feu entrante sur le réseau source. En termes génériques (vos paramètres réseau spécifiques peuvent être différents), procédez comme suit:
Ouvrez les règles de pare-feu réseau de votre machine de base de données source.
Créez une règle entrante.
Définissez le type de règle sur MySQL.
Définissez le protocole sur TCP.
Définissez la plage de ports sur 3306.
Définissez l'adresse IP source sur l'adresse IP sortante de la base de données de destination. Exemple : 12.20.36.126/32. (La désignation /32 au format CIDR limite la plage d'adresses à une seule adresse, celle fournie. Il définit le masque de sous-réseau sur 255.255.255.255. Si l'instance Cloud SQL que vous avez créée est une instance haute disponibilité, incluez les adresses IP sortantes de l'instance principale et de l'instance secondaire.
Enregistrez la règle de pare-feu, puis quittez l'outil.
Nous vous recommandons également vivement d'utiliser SSL/TLS lors de la définition du profil de connexion de la source afin que les données envoyées à la source et reçues par celle-ci soient sécurisées.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/05 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/05 (UTC)."],[[["\u003cp\u003ePublic IP connectivity is suitable when the source database is outside Google Cloud and has an externally accessible IPv4 address and TCP port.\u003c/p\u003e\n"],["\u003cp\u003eFor source databases external to Google Cloud, add the destination database's outgoing IP address and port 3306 as an inbound firewall rule on the source network.\u003c/p\u003e\n"],["\u003cp\u003eThe source IP address in the inbound rule should be set to the destination database's outgoing IP address, using CIDR notation such as \u003ccode\u003e12.20.36.126/32\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIf the Cloud SQL instance is high availability, include the outgoing IP addresses for both the primary and secondary instances in the firewall rule.\u003c/p\u003e\n"],["\u003cp\u003eUsing SSL/TLS during source connection profile definition is highly recommended to secure data transmission.\u003c/p\u003e\n"]]],[],null,["# Configure connectivity using IP allowlists\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nMySQL \\| [PostgreSQL](/database-migration/docs/postgres/configure-connectivity-ip-allowlists \"View this page for the PostgreSQL version of Database Migration Service.\") \\| [PostgreSQL to AlloyDB](/database-migration/docs/postgresql-to-alloydb/configure-connectivity-ip-allowlists \"View this page for the PostgreSQL to AlloyDB version of Database Migration Service.\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nOverview\n--------\n\nPublic IP connectivity is most appropriate when the source database is external to Google Cloud\nand has an externally accessible IPv4 address and TCP port. If the source\ndatabase is hosted in another VPC in Google Cloud, then the easiest way to\nconnect the source database with the Cloud SQL instance is by using VPC Peering.\n\nIf your source database is external to Google Cloud, then add the destination database's **outgoing\nIP address** (and port 3306) as an inbound firewall rule on the source network. In\ngeneric terms (your specific network settings may differ), do the following:\n\n1. Open the source database machine's network firewall rules.\n\n2. Create an inbound rule.\n\n3. Set the Rule type to `MySQL`.\n\n4. Set the Protocol to `TCP`.\n\n5. Set the Port range to 3306.\n\n6. Set the Source IP address to the destination database's **outgoing IP address** . For example:\n `12.20.36.126/32`. (The /32 designation in CIDR notation limits the\n address range to one address only, the one provided. It's setting the subnet\n mask to `255.255.255.255`). If the Cloud SQL instance you created\n is a high availability instance, include the outgoing IP addresses for both\n the primary and the secondary instance.\n\n\n You can use the **SQL Instances** page in the Google Cloud Console to [locate the outgoing IP addresses](/database-migration/docs/mysql/debugging-connectivity#locateoutgoingIPaddress).\n\n \u003cbr /\u003e\n\n7. Save the firewall rule and exit.\n\n| You can test connectivity by adding another, temporary inbound firewall rule using the IP address of your local machine (or `0.0.0.0/0` to allow access from anywhere), and then running the following telnet command: `telnet [SOURCE_DB_IP_ADDRESS] 3306`. The connection should succeed. Delete the temporary firewall rule.\n\nIt's also highly recommended to use SSL/TLS during the definition of the source\nconnection profile so that the data sent to and received by the source is\nsecure.\n[Learn more](/sql/docs/mysql/authorize-ssl) about SSL/TLS certificates for MySQL."]]