You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"To create the `batman` database user that is used throughout the notebook, run the following `gcloud` command."
328
+
"### 🧑🍳 Create a Chef Database User\n",
329
+
"To create the `chef` database user that is used throughout the notebook, run the following `gcloud` command."
332
330
]
333
331
},
334
332
{
@@ -337,9 +335,9 @@
337
335
"id": "9NYmcepFOM12"
338
336
},
339
337
"source": [
340
-
"!gcloud sql users create batman\\\n",
338
+
"!gcloud sql users create chef\\\n",
341
339
" --instance={instance_name} \\\n",
342
-
" --password=\"robin\""
340
+
" --password=\"food\""
343
341
],
344
342
"execution_count": null,
345
343
"outputs": []
@@ -370,9 +368,9 @@
370
368
},
371
369
"source": [
372
370
"### 🎟 **Configuring Credentials**\n",
373
-
"The Cloud SQL Python Connector uses [**Application Default Credentials (ADC)**](https://cloud.google.com/docs/authentication) strategy for resolving credentials.\n",
371
+
"The Cloud SQL Python Connector uses [**Application Default Credentials (ADC)**](https://cloud.google.com/docs/authentication) strategy for resolving credentials.\n",
374
372
"\n",
375
-
"> 💡 Using the Python Connector in Cloud Run, App Engine, or Cloud Functions will automatically use the service account deployed with each service, allowing this step to be skipped. ✅\n",
373
+
"> 💡 Using the Python Connector in Cloud Run, App Engine, or Cloud Functions will automatically use the service account deployed with each service, allowing this step to be skipped. ✅\n",
376
374
"\n",
377
375
"Please see the [google.auth](https://google-auth.readthedocs.io/en/master/reference/google.auth.html) package documentation for more information on how these credentials are sourced.\n",
378
376
"\n",
@@ -391,7 +389,7 @@
391
389
},
392
390
"source": [
393
391
"### 💻 **Install Code Dependencies**\n",
394
-
"It is recommended to use the Connector alongside a library that can create connection pools, such as [SQLAlchemy](https://www.sqlalchemy.org/).\n",
392
+
"It is recommended to use the Connector alongside a library that can create connection pools, such as [SQLAlchemy](https://www.sqlalchemy.org/).\n",
395
393
"This will allow for connections to remain open and be reused, reducing connection overhead and the number of connections needed\n",
396
394
"\n",
397
395
"Let's `pip install` the [Cloud SQL Python Connector](https://github.com/GoogleCloudPlatform/cloud-sql-python-connector) as well as [SQLAlchemy](https://www.sqlalchemy.org/), using the below command."
"print(f\"Your instance connection name is: {INSTANCE_CONNECTION_NAME}\")\n",
445
-
"DB_USER = \"batman\"\n",
446
-
"DB_PASS = \"robin\"\n",
447
-
"DB_NAME = \"movies\""
443
+
"DB_USER = \"chef\"\n",
444
+
"DB_PASS = \"food\"\n",
445
+
"DB_NAME = \"sandwiches\""
448
446
],
449
447
"execution_count": null,
450
448
"outputs": []
@@ -458,12 +456,12 @@
458
456
"### ✅ **Basic Usage**\n",
459
457
"To connect to Cloud SQL using the connector, initialize a `Connector` object and call its `connect` method with the proper input parameters.\n",
460
458
"\n",
461
-
"The `connect` method takes in the parameters we previously defined, as well as a few additional parameters such as:\n",
459
+
"The `connect` method takes in the parameters we previously defined, as well as a few additional parameters such as:\n",
462
460
"* `driver`: The name of the database driver to connect with.\n",
463
461
"* `ip_type` (optional): The IP type (public or private) used to connect. IP types can be either `IPTypes.PUBLIC` or `IPTypes.PRIVATE`. ([Example](#scrollTo=yjAPpIDdRfu2))\n",
464
462
"* `enable_iam_auth`: (optional) Boolean enabling IAM based authentication. ([Example](#scrollTo=GpVKrv0TCXje))\n",
465
463
"\n",
466
-
"Let's show an example! 🤘 🙌"
464
+
"Let's show an example! 🤘 🙌"
467
465
]
468
466
},
469
467
{
@@ -517,25 +515,27 @@
517
515
"source": [
518
516
"# connect to connection pool\n",
519
517
"with pool.connect() as db_conn:\n",
520
-
" # create ratings table in our movies database\n",
518
+
" # create ratings table in our sandwiches database\n",
521
519
" db_conn.execute(\n",
520
+
" sqlalchemy.text(\n",
522
521
"\"CREATE TABLE IF NOT EXISTS ratings \"\n",
523
-
"\"( id SERIAL NOT NULL, title VARCHAR(255) NOT NULL, \"\n",
524
-
"\"genre VARCHAR(255) NOT NULL, rating FLOAT NOT NULL, \"\n",
522
+
"\"( id SERIAL NOT NULL, name VARCHAR(255) NOT NULL, \"\n",
523
+
"\"origin VARCHAR(255) NOT NULL, rating FLOAT NOT NULL, \"\n",
525
524
"\"PRIMARY KEY (id));\"\n",
525
+
" )\n",
526
526
" )\n",
527
527
" # insert data into our ratings table\n",
528
528
" insert_stmt = sqlalchemy.text(\n",
529
-
"\"INSERT INTO ratings (title, genre, rating) VALUES (:title, :genre, :rating)\",\n",
529
+
"\"INSERT INTO ratings (name, origin, rating) VALUES (:name, :origin, :rating)\",\n",
" results = db_conn.execute(\"SELECT * FROM ratings\").fetchall()\n",
538
+
" results = db_conn.execute(sqlalchemy.text(\"SELECT * FROM ratings\")).fetchall()\n",
539
539
"\n",
540
540
" # show results\n",
541
541
" for row in results:\n",
@@ -582,13 +582,13 @@
582
582
"id": "GCsS4f5UCYUa"
583
583
},
584
584
"source": [
585
-
"### 🪪 IAM Database Authentication\n",
585
+
"### 🪪 IAM Database Authentication\n",
586
586
"\n",
587
-
"[Automatic IAM database authentication](https://cloud.google.com/sql/docs/mysql/authentication#automatic) is supported for **MySQL** Cloud SQL instances.\n",
587
+
"[Automatic IAM database authentication](https://cloud.google.com/sql/docs/mysql/authentication#automatic) is supported for **MySQL** Cloud SQL instances.\n",
588
588
"\n",
589
589
"> 💡 This allows an IAM user to establish an authenticated connection to a MySQL database without having to set a password and enabling the `enable_iam_auth` parameter in the connector's `connect` method.\n",
590
590
"\n",
591
-
"> 🚨 If you are using a pre-existing Cloud SQL instance within this notebook you may need to [configure Cloud SQL instance to allow IAM authentication](https://cloud.google.com/sql/docs/mysql/create-edit-iam-instances#configuring_existing_instances_for) by setting the `cloudsql_iam_authentication` database flag to `On`.\n",
591
+
"> 🚨 If you are using a pre-existing Cloud SQL instance within this notebook you may need to [configure Cloud SQL instance to allow IAM authentication](https://cloud.google.com/sql/docs/mysql/create-edit-iam-instances#configuring_existing_instances_for) by setting the `cloudsql_iam_authentication` database flag to `On`.\n",
592
592
"(Cloud SQL instances created within this notebook already have it enabled)\n"
0 commit comments