Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedsami1976 committed Jul 5, 2023
1 parent 0cfdf73 commit 06731fe
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 43 deletions.
12 changes: 12 additions & 0 deletions databases/python/.ipynb_checkpoints/postgresql_py-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "69ecea85-c1f6-4682-9b27-f766a8bfbb80",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"!sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config libpq-dev -y"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
192 changes: 168 additions & 24 deletions databases/python/mysql_py.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,84 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "d7eadf1c-ab8d-4c4d-b759-f6df6bd10a4e",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reading package lists... Done\n",
"Building dependency tree... Done\n",
"Reading state information... Done\n",
"build-essential is already the newest version (12.9ubuntu3).\n",
"python3-dev is already the newest version (3.10.6-1~22.04).\n",
"The following NEW packages will be installed:\n",
" default-libmysqlclient-dev pkg-config\n",
"0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.\n",
"Need to get 51.8 kB of archives.\n",
"After this operation, 144 kB of additional disk space will be used.\n",
"Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 default-libmysqlclient-dev amd64 1.0.8 [3,586 B]\n",
"Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 pkg-config amd64 0.29.2-1ubuntu3 [48.2 kB]\n",
"Fetched 51.8 kB in 1s (76.1 kB/s) \n",
"debconf: delaying package configuration, since apt-utils is not installed\n",
"Selecting previously unselected package default-libmysqlclient-dev:amd64.\n",
"(Reading database ... 50966 files and directories currently installed.)\n",
"Preparing to unpack .../default-libmysqlclient-dev_1.0.8_amd64.deb ...\n",
"Unpacking default-libmysqlclient-dev:amd64 (1.0.8) ...\n",
"Selecting previously unselected package pkg-config.\n",
"Preparing to unpack .../pkg-config_0.29.2-1ubuntu3_amd64.deb ...\n",
"Unpacking pkg-config (0.29.2-1ubuntu3) ...\n",
"Setting up default-libmysqlclient-dev:amd64 (1.0.8) ...\n",
"Setting up pkg-config (0.29.2-1ubuntu3) ...\n"
]
}
],
"source": [
"!sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config -y"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "2df03dd8-0636-4057-8cbe-6e8ef53d59d9",
"metadata": {
"scrolled": true
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting mysql-connector-python\n",
" Using cached mysql_connector_python-8.0.33-cp311-cp311-manylinux1_x86_64.whl (27.4 MB)\n",
"Collecting protobuf<=3.20.3,>=3.11.0 (from mysql-connector-python)\n",
" Using cached protobuf-3.20.3-py2.py3-none-any.whl (162 kB)\n",
"Installing collected packages: protobuf, mysql-connector-python\n",
" Attempting uninstall: protobuf\n",
" Found existing installation: protobuf 4.21.12\n",
" Uninstalling protobuf-4.21.12:\n",
" Successfully uninstalled protobuf-4.21.12\n",
"Successfully installed mysql-connector-python-8.0.33 protobuf-3.20.3\n",
"Requirement already satisfied: sqlalchemy in /opt/conda/lib/python3.11/site-packages (2.0.15)\n",
"Requirement already satisfied: typing-extensions>=4.2.0 in /opt/conda/lib/python3.11/site-packages (from sqlalchemy) (4.6.3)\n",
"Requirement already satisfied: greenlet!=0.4.17 in /opt/conda/lib/python3.11/site-packages (from sqlalchemy) (2.0.2)\n",
"Collecting PyMySQL\n",
" Using cached PyMySQL-1.1.0-py3-none-any.whl (44 kB)\n",
"Installing collected packages: PyMySQL\n",
"Successfully installed PyMySQL-1.1.0\n",
"Collecting mysqlclient\n",
" Using cached mysqlclient-2.2.0-cp311-cp311-linux_x86_64.whl\n",
"Installing collected packages: mysqlclient\n",
"Successfully installed mysqlclient-2.2.0\n",
"Collecting configparser\n",
" Using cached configparser-5.3.0-py3-none-any.whl (19 kB)\n",
"Installing collected packages: configparser\n",
"Successfully installed configparser-5.3.0\n"
]
}
],
"source": [
"!pip install mysql-connector-python\n",
"!pip install sqlalchemy\n",
Expand All @@ -36,10 +98,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "64a65b56-4a2e-4dff-8ebc-a462629ebee1",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter username: root\n",
"Enter password: ········\n"
]
}
],
"source": [
"from mysql.connector import connect, Error\n",
"from getpass import getpass\n",
Expand Down Expand Up @@ -69,10 +140,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "347927a0-bd5c-42c7-b7e0-6ffadfdb1bae",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<mysql.connector.connection_cext.CMySQLConnection object at 0x7f3090556e10>\n"
]
}
],
"source": [
"mysqldb = connect(\n",
" host=\"mysql-db\",\n",
Expand All @@ -86,10 +165,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "5f003bef-64ac-4882-8389-d0e4eb1f5582",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('information_schema',), ('mysql',), ('performance_schema',), ('sys',), ('testdb',)]\n"
]
}
],
"source": [
"mysqldb = connect(\n",
" host=\"mysql-db\",\n",
Expand All @@ -109,7 +196,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "6fce2f16-cecd-40e5-a68e-51acbc45b352",
"metadata": {},
"outputs": [],
Expand All @@ -128,10 +215,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "abc1fcb4-3d0f-424b-a3f4-49906ac9ccbd",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('information_schema',), ('mysql',), ('performance_schema',), ('sys',), ('testdb',)]\n"
]
}
],
"source": [
"mysqldb = connect(\n",
" host=\"mysql-db\",\n",
Expand All @@ -156,7 +251,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "92c72faa-e76f-4039-af6d-f864cf80d6e7",
"metadata": {},
"outputs": [],
Expand All @@ -180,10 +275,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "a0f324e5-aa5b-4095-9e30-c9146993f5d6",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('id', b'int', 'YES', '', None, '')\n",
"('first_name', b'varchar(20)', 'YES', '', None, '')\n"
]
}
],
"source": [
"mysqldb = connect(\n",
" host=\"mysql-db\",\n",
Expand All @@ -207,10 +311,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "7137d501-f3e2-4279-b0a5-48cdd7aaec50",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(1, 'ahmed'), (2, 'aya'), (3, 'john')]\n"
]
}
],
"source": [
"mysqldb = connect(\n",
" host=\"mysql-db\",\n",
Expand All @@ -234,10 +346,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "0c69a2c8-9a6f-40fe-b592-09cb739c50e2",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mycursor.close()"
]
Expand All @@ -252,7 +375,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "21bfbd6d-f8e1-4e6a-86e8-72c0fa628f55",
"metadata": {},
"outputs": [],
Expand All @@ -263,7 +386,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "9c599431-bd0f-40b8-88b8-f3259ec0933c",
"metadata": {},
"outputs": [],
Expand All @@ -274,10 +397,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "de246924-2dc7-400b-ae8b-0c7e8e09cace",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2023-07-05 04:23:34,596 INFO sqlalchemy.engine.Engine SELECT DATABASE()\n",
"2023-07-05 04:23:34,596 INFO sqlalchemy.engine.Engine [raw sql] ()\n",
"2023-07-05 04:23:34,597 INFO sqlalchemy.engine.Engine SELECT @@sql_mode\n",
"2023-07-05 04:23:34,597 INFO sqlalchemy.engine.Engine [raw sql] ()\n",
"2023-07-05 04:23:34,598 INFO sqlalchemy.engine.Engine SELECT @@lower_case_table_names\n",
"2023-07-05 04:23:34,599 INFO sqlalchemy.engine.Engine [raw sql] ()\n",
"2023-07-05 04:23:34,600 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n",
"2023-07-05 04:23:34,600 INFO sqlalchemy.engine.Engine SHOW DATABASES;\n",
"2023-07-05 04:23:34,600 INFO sqlalchemy.engine.Engine [generated in 0.00071s] ()\n",
"('information_schema',)\n",
"('mysql',)\n",
"('performance_schema',)\n",
"('sys',)\n",
"('testdb',)\n"
]
}
],
"source": [
"conn = engine.connect()\n",
"#conn.execute(\"CREATE DATABASE testdb;\")\n",
Expand Down
Loading

0 comments on commit 06731fe

Please sign in to comment.