How to Select mysql database on CentOS/RHEL/Oracle server step by step guide for beginner


In this article we learn how to select mysql database on linux server.After connected the mysql server we need to select database with which we are working among all databases on the mysql server. To select the database we execute “use” command through mysql promt.

Select database using mysql promt

To select the database using mysql promt we login the mysql server and execute the below command through mysql promt.

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use techrideradmin
Database changed
How to Select mysql database on CentOS/RHEL/Oracle server step by step guide for beginner

     How to Select mysql database on CentOS/RHEL/Oracle server step by step guide for beginner

Select database using using php script

To select database using php script we use mysql_select_db  function .
Lets take an example to select database using php script.
<html>
   <head>
      <title>Select MySQL database on linux system</title>
   </head>
   <body>
      <?php
         $mysql_host = 'localhost';
         $mysql_user = 'root';
         $mysql_pass = 'passwordofroot';
         $conn = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
        
         if(! $conn ) {
            die('Could not connect the server: ' . mysql_error());
         }
         echo 'Connection successfully established';
         mysql_select_db(‘techrideradmin’);
         mysql_close($conn);
      ?>
   </body>
</html>

That’s all.If this article is helpful please share it!!!!


SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment