{"id":396,"date":"2014-06-12T00:27:57","date_gmt":"2014-06-12T00:27:57","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=396"},"modified":"2023-03-16T14:24:56","modified_gmt":"2023-03-16T19:24:56","slug":"some-basic-mysql-commands","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/some-basic-mysql-commands\/","title":{"rendered":"Some Basic MySQL Commands"},"content":{"rendered":"<p><strong>Enter Mysql<\/strong><\/p>\n<pre>mysql -u root -p<\/pre>\n<p><strong>Create Database<\/strong><\/p>\n<pre>create DATABASE testdb;<\/pre>\n<p><strong>Select Database<\/strong><\/p>\n<pre>use testdb;<\/pre>\n<p><strong>Delete Database<\/strong><\/p>\n<pre>drop DATABASE testdb;<\/pre>\n<p><strong>Drop Table<\/strong><\/p>\n<pre>drop table table_name;<\/pre>\n<p><strong>Show Tables<\/strong><\/p>\n<pre>show tables;<\/pre>\n<p><strong>Show data in table <\/strong><\/p>\n<pre>SELECT * FROM table_name;<\/pre>\n<p><strong>Create Table<\/strong><\/p>\n<pre>CREATE TABLE contacts_table (id INT, name VARCH<code>AR(20), email VARCHAR(20)<\/code><strong><code>);<\/code><\/strong><\/pre>\n<h2><strong>Insert data into table<\/strong><\/h2>\n<pre>INSERT INTO contacts_table (id,name,email) VALUES(2,\"John\",\"John83@incredigeek.com\");<\/pre>\n<p><strong>List one row in table<\/strong><\/p>\n<pre>SELECT * FROM table_name LIMIT 1;<\/pre>\n<p><strong>Delete Row in Table<\/strong><\/p>\n<pre>DELETE FROM table_name WHERE row_name=data_to_delete;<\/pre>\n<p><strong>Delete all &#8220;users&#8221; from a WordPress database that do not contain admin in the username.<\/strong><\/p>\n<pre>DELETE FROM `wp-users` WHERE user_login NOT LIKE \"%admin%\"<\/pre>\n<p><strong>Add Auto Increment to Table<\/strong><\/p>\n<pre><code>ALTER TABLE  `table_name` ADD  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;<\/code><\/pre>\n<p><strong>Create table with Date and Time timestamp<\/strong><\/p>\n<pre>CREATE TABLE table_name (id INT, timeStamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP);<\/pre>\n<p><strong>Show MySQL Users<\/strong><\/p>\n<pre>select * from mysql.users;<\/pre>\n<p><strong>Create MySQL User<\/strong><\/p>\n<pre>GRANT ALL ON mysqldb.* TO username@localhost IDENTIFIED BY 'password';<\/pre>\n<p><strong>Delete MySQL user<\/strong><\/p>\n<pre>DROP USER 'username'@'localhost';<\/pre>\n<p><strong>Add Column to the end of MySQL Table<\/strong><\/p>\n<pre>ALTER TABLE mysqltable ADD email VARCHAR(60);<\/pre>\n<p><strong>Add Column to the begging of MySQL Table<\/strong><\/p>\n<pre>ALTER TABLE mysqltable ADD email VARCHAR(60) FIRST;<\/pre>\n<p><strong>Insert Column after Specific Column in MySQL Table<\/strong><\/p>\n<pre>ALTER TABLE mysqltable ADD email VARCHAR(60) AFTER columnname;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Enter Mysql mysql -u root -p Create Database create DATABASE testdb; Select Database use testdb; Delete Database drop DATABASE testdb; Drop Table drop table table_name; Show Tables show tables; Show data in table SELECT * FROM table_name; Create Table CREATE &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/some-basic-mysql-commands\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,135],"tags":[137,138,136,139],"class_list":["post-396","post","type-post","status-publish","format-standard","hentry","category-linux","category-mysql","tag-create-database","tag-database","tag-mysql-2","tag-show-tables"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=396"}],"version-history":[{"count":13,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/396\/revisions"}],"predecessor-version":[{"id":4884,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/396\/revisions\/4884"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}