{"id":1507,"date":"2017-02-01T05:50:07","date_gmt":"2017-02-01T05:50:07","guid":{"rendered":"http:\/\/www.fastwebhost.in\/blog\/?p=1507"},"modified":"2019-01-22T12:30:14","modified_gmt":"2019-01-22T12:30:14","slug":"how-to-select-mysql-database-linux-via-command-line","status":"publish","type":"post","link":"https:\/\/www.fastwebhost.in\/blog\/how-to-select-mysql-database-linux-via-command-line\/","title":{"rendered":"How to Select a MySQL Database on Linux via Command Line"},"content":{"rendered":"<p>In this tutorial you are going to learn how to select a MySQL database via command line on Linux server. Also, you&#8217;ll learn basic MySQL database operations through below steps.<\/p>\n<p>Let&#8217;s get straight to the point.<\/p>\n<h4>How to access MySQL command line or shell?<\/h4>\n<p>If MySQL server already installed on your server, then you can access it through shell or command line.<\/p>\n<p>First, login to the server as a root and then enter below command to access MySQL shell interface.<\/p>\n<p>You can use any of the below commands to access MySQL command line.<\/p>\n<p>mysqlmysql -u root -p<\/p>\n<p>In the above command <span>u<\/span> flag indicates root user, and <span>-p<\/span> flag for password authentication.<\/p>\n<p>You have to enter password to access MySQL.<\/p>\n<p>mysql&gt;<\/p>\n<p>Now, you are ready to select a database and work on it!<\/p>\n<h3>MySQL Database Command Line Basics<\/h3>\n<p><span><\/span><\/p>\n<ul data-unit=\"px\" style=\"margin-bottom: 10px !important;\">\n<li><a href=\"https:\/\/www.fastwebhost.in\/blog\/how-to-change-reset-mysql-root-password-linux-via-command-line\/\" target=\"_blank\" rel=\"nofollow\">How to Change or Reset MySQL root Password via Command Line<\/a><\/li>\n<\/ul>\n<ul data-unit=\"px\" style=\"margin-bottom: 10px !important;\">\n<li><a href=\"https:\/\/www.fastwebhost.in\/blog\/how-to-create-a-mysql-database-via-command-line\/amp\" target=\"_blank\" rel=\"nofollow\">How to Create a MySQL Database via Command Line<\/a><\/li>\n<\/ul>\n<ul>\n<li><a href=\"https:\/\/www.fastwebhost.in\/blog\/how-to-select-mysql-database-linux-via-command-line\/amp\" target=\"_blank\" rel=\"nofollow\">How to Select a MySQL Database via Command Line<\/a><\/li>\n<\/ul>\n<ul>\n<li><a href=\"https:\/\/www.fastwebhost.in\/blog\/how-to-delete-a-mysql-database-on-linux-via-command-line\/amp\" target=\"_blank\" rel=\"nofollow\">How to Delete a MySQL Database via Command Line<\/a><\/li>\n<\/ul>\n<ul>\n<li><a href=\"https:\/\/www.fastwebhost.in\/blog\/how-to-backup-mysql-databases-via-command-line\/amp\" target=\"_blank\" rel=\"nofollow\">How to Backup or Restore a MySQL Database via Command Line<\/a><\/li>\n<\/ul>\n<h3>How to Select a MySQL Database?<\/h3>\n<p>When you are working on MySQL databases through command line, you have to select a database on which you are going execute SQL queries. Creating a database does not select it for use; you must do that explicitly.<\/p>\n<p><a href=\"http:\/\/www.fastwebhost.in\/blog\/how-to-create-a-mysql-database-via-command-line\/\" target=\"_blank\">If you haven&#8217;t yet created database follow this article.<\/a><\/p>\n<p>To make a database &#8220;sampledb&#8221; the current database, execute this below query:<\/p>\n<p>mysql&gt; USE sampledb;<\/p>\n<p>Your database needs to be created only once, but you must <span>select<\/span> it for use each time you begin a <span>mysql<\/span> session. You can do this by issuing a <span>USE<\/span> statement as shown in the example.<\/p>\n<p>The above command gives you following output and shows that database has changed.<\/p>\n<p>mysql&gt; USE sampledb;Database changed<\/p>\n<p>You can verify the database has been selected by executing the following command.<\/p>\n<p>mysql&gt; SELECT database();+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+| database()        |+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+| sampledb          |+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+1 row in set (0.00 sec)<\/p>\n<p><span>TIP:<\/span> All the database names, table names, table fields name are case sensitive. So you would have to use proper names while giving any SQL command.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial you are going to learn how to select a MySQL database via command line on Linux server. Also, you&#8217;ll learn basic MySQL database operations through below steps. Let&#8217;s get straight to the point. How to access MySQL command line or shell? If MySQL server already installed on your server, then you can [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1521,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[22,20],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts\/1507"}],"collection":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/comments?post=1507"}],"version-history":[{"count":3,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts\/1507\/revisions"}],"predecessor-version":[{"id":4723,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts\/1507\/revisions\/4723"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/media\/1521"}],"wp:attachment":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/media?parent=1507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/categories?post=1507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/tags?post=1507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}