Avance Zone

Connection of Database from Linux shell

mysql advantages and Connectivity from unix / linux shell 

•Ability to handle an unlimited number of simultaneous users.
•Capacity to handle 50,000,000+ records.
•Very fast command execution, perhaps the fastest to be found on the market.
•Easy and efficient user privilege system.

                Connect mysql from linux shell :
shell> mysql ?u arvind –p
where arvind is the username
(might work for root for username)
Enter password when prompted.

                To select database in mysql

mysql> use mydb;
Result:
Database changed Mydb>
You now are connected to mydb database

                Create table in mysql :


mysql> CREATE TABLE test ( > name VARCHAR (15), > email VARCHAR (25), > phone_number
INT, > ID INT NOT NULL AUTO_INCREMENT, > PRIMARY KEY (ID));

                Insert command in mysql :

mysql> INSERT INTO test VALUES mysql> (’Bugs Bunny’, ‘carrots@devshed.com’, mysql> 5554321,NULL);

                Delete a record from mysql table

mysql> DELETE FROM test mysql> WHERE (name = “arvind”);

Update a record in mysql database :

mysql> UPDATE test SET name = ‘arvind1′ mysql> WHERE name = “arvind2″;

arvind2 will be replace with arvind1

                selection and order by mysql :?
mysql> SELECT * FROM test WHERE mysql> (name = “arvind”) ORDER BY mysql>
phone_number;

MySql php Connection

<div id="Avance Zone">
<?php
echo "php started.....";
$sqlConn = mysql_connect('localhost', 'dbuname', 'dbpwd');
//this is comment
//dbuname is the database username
//dbpwd is the database password
if (!$sqlConn)
{
die('Connect error'.mysql_error());
//the error will be displayed if php cannt connet to your database
}
else
{
echo "Connected";
//connected will be displayed once your php connected with mysql
}
//$query = "show databases;";
//select which database you want to edit
$db=mysql_select_db("dbname");
//dbname is the database name
if(!$db)
{
die('mysql select error'.mysql_error());
//if db cannot be connected this shows this message
}
//select the table
$result = mysql_query("select * from R");
$numofrows = mysql_num_rows($result);
echo "No of rows".$numofrows;
echo "<br>";
echo "<table border='1'>
<tr>
<th>FirstName</th>
<th>Lastname</th>
<th>City</th>
<th>Mobile</th>
<th>email</th>
<th>pre_emp</th>
<th>Experience</th>
<th>Qualification</th>
<th>college</th>
<th>skill set</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['first_name'] . "</td>";
echo "<td>" . $row['last_name'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['mobile'] . "</td>";
echo "<td>" . $row['email1'] . "</td>";
echo "<td>" . $row['department'] . "</td>";
echo "<td>" . $row['Experience'] . "</td>";
echo "<td>" . $row['previous_employer'] . "</td>";
echo "<td>" . $row['college'] . "</td>";
echo "<td>" . $row['skillset'] . "</td>";
echo "</tr>";
}
echo "</TABLE>";
mysql_close($sqlConn);
?>
</div>

Avance Zone