Thursday, November 6, 2008

Running MySQL in Windows

Step 1: Open Command Prompt
C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -p

Step 2:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hibernatetutorial |
...

The above command shows all the existing databases.

Step 3:
Create new MySQL user
CREATE USER 'sark'@'localhost' IDENTIFIED BY 'sark';

Step 4:
Grant Permissions.
GRANT ALL PRIVILEGES ON *.* TO 'sark'@'localhost' IDENTIFIED BY 'sark' WITH GRANT OPTION;


Step 5:
To check the existing users.
mysql> select User,Host from mysql.user;
+-----------+--------------+
| User | Host |
+-----------+--------------+
| root | % |
| sark | localhost |
+-----------+--------------+

Step 6: To check the Permissions/privileges.

mysql> show grants for sark@localhost;
+-------------------------------------------------------------------------------
-------------------------------------------------------+
| Grants for sark@localhost
|
+-------------------------------------------------------------------------------
-------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'sark'@'localhost' IDENTIFIED B
Y PASSWORD '*A231ED0CF53E6EF33A1A79930EB2A82DB89812F2' |
+-------------------------------------------------------------------------------
-------------------------------------------------------+

Step 6:
Exit from root user and login as 'sark' user;

mysql> exit;
Bye

C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -usark -psark
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 43 to server version: 5.0.24-community-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Step 7:
Create database 'sarkDB'
mysql> CREATE DATABASE sarkDB;

Step 8:
Use Database
mysql> use sarkDB;
Database changed

Step 9:
Create table demo_people.
mysql> CREATE TABLE `demo_people` (
`pid` int(11) NOT NULL,
`name` varchar(20) default NULL,
`phone` int(11) default NULL,
PRIMARY KEY (`pid`)
);
Query OK, 0 rows affected (0.23 sec)

mysql>

No comments: