Skip to Content

Mysql Basics

Ahmed Hashim's picture

Start MySql

$su
$/etc/init.d/mysqld start
Starting MySQL:                                            [  OK  ]

Open mysql command line :

$ mysql -u root -p
password : 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 4.0.20
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

if root haven't password remove -p

Show Databases :

mysql> show databases;
+----------+
| Database |
+---------- +
| drupal    |
| mysql     |
| test      |
| tmp       |
+----------+
*mysql>

Open database :

mysql> use mysql;
Reading table information for completion of table and column names
Database changed
mysql>

Read table information:

mysql>show tables;
+-----------------+
| Tables_in_mysql |
+-----------------+
| columns_priv    |
| db              |
| func            |
| host            |
| tables_priv     |
| user            |
+-----------------+
6 rows in set (0.00 sec)
mysql>

Create new Database:

mysql> create database hazem;
Query OK, 1 row affected (0.16 sec)
mysql>

Create Tables:

mysql> create table Friends(id integer , name char(20));
Query OK, 0 rows affected (0.01 sec)
mysql>

Insert Data into table:

mysql> insert into Friends values(1,'alaa');
Query OK, 1 row affected (0.00 sec)
mysql>

Read information of table :

mysql> select * from Friends;
+------+-----------+
| id   | name      |
+------+-----------+
|    1 | alaa      |
|    2 | manal     |
|    3 | MSameer   |
|    3 | OneOfOne  |
|    3 | BlueViper |
|    3 | Yousef    |
+------+-----------+
6 rows in set (0.07 sec)
mysql>

Delete Table :

mysql> drop tablen Friends;
Query OK, 0 rows affected (0.05 sec)
mysql>

Drop Database

mysql> drop database mysql;
mysql>

Close Mysql :

mysql>\q
Bye
$


Dr. Radut | book