
{"id":19170,"date":"2022-08-27T22:17:51","date_gmt":"2022-08-27T16:47:51","guid":{"rendered":"https:\/\/valavil.in\/?p=19170"},"modified":"2022-08-27T22:17:51","modified_gmt":"2022-08-27T16:47:51","slug":"create-table-on-a-database-using-python-and-mysql","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2022\/08\/27\/create-table-on-a-database-using-python-and-mysql\/","title":{"rendered":"Create table on a database using python and MySQL"},"content":{"rendered":"\n<p>  <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$python3  dt.py\n$cat dt.py \n# importing required library\nimport mysql.connector\n\n# connecting to the database\ndataBase = mysql.connector.connect(\n\t\t\t\t\thost = \"localhost\",\n\t\t\t\t\tuser = \"jeff\",\n\t\t\t\t\tpasswd = \"sixer\",\n\t\t\t\t\tdatabase = \"learning\" )\n\n# preparing a cursor object\ncursorObject = dataBase.cursor()\n\n# creating table\nstudentRecord = \"\"\"CREATE TABLE STUDENT (\n\t\t\t\tNAME VARCHAR(20) NOT NULL,\n\t\t\t\tBRANCH VARCHAR(50),\n\t\t\t\tROLL INT NOT NULL,\n\t\t\t\tSECTION VARCHAR(5),\n\t\t\t\tAGE INT\n\t\t\t\t)\"\"\"\n\n# table created\ncursorObject.execute(studentRecord)\n\n# disconnecting from server\ndataBase.close()\n$mysql --user=jeff -psixer\nmysql: [Warning] Using a password on the command line interface can be insecure.\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 9\nServer version: 8.0.30-1 (Debian)\n\nCopyright (c) 2000, 2022, Oracle and\/or its affiliates.\n\nOracle is a registered trademark of Oracle Corporation and\/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nmysql&gt; use learning;\nReading table information for completion of table and column names\nYou can turn off this feature to get a quicker startup with -A\n\nDatabase changed\nmysql&gt; show tables;\n+--------------------+\n| Tables_in_learning |\n+--------------------+\n| STUDENT            |\n+--------------------+\n1 row in set (0.00 sec)\n\nmysql&gt; desc STUDENT;\n+---------+-------------+------+-----+---------+-------+\n| Field   | Type        | Null | Key | Default | Extra |\n+---------+-------------+------+-----+---------+-------+\n| NAME    | varchar(20) | NO   |     | NULL    |       |\n| BRANCH  | varchar(50) | YES  |     | NULL    |       |\n| ROLL    | int         | NO   |     | NULL    |       |\n| SECTION | varchar(5)  | YES  |     | NULL    |       |\n| AGE     | int         | YES  |     | NULL    |       |\n+---------+-------------+------+-----+---------+-------+\n5 rows in set (0.20 sec)\n\nmysql&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>$python3 dt.py $cat dt.py # importing required library import mysql.connector # connecting to the database dataBase = mysql.connector.connect( host = &#8220;localhost&#8221;, user = &#8220;jeff&#8221;, passwd = &#8220;sixer&#8221;, database = &#8220;learning&#8221; ) # preparing a cursor object cursorObject = dataBase.cursor() # creating table studentRecord = &#8220;&#8221;&#8221;CREATE TABLE STUDENT ( NAME VARCHAR(20) NOT NULL, BRANCH VARCHAR(50), ROLL &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2022\/08\/27\/create-table-on-a-database-using-python-and-mysql\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Create table on a database using python and MySQL&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/19170"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=19170"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/19170\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=19170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=19170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=19170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}