Tuesday, April 20, 2010

MYSQL


#mysqladmin -u password <== to set the user password in mysql as root @ user
eg:-#mysqladmin -u root password 123

#mysqladmin -u -p password <== to reset the password in sql
eg:-#mysqladmin -u root -p123 password 321

#mysql -u -p <== to login mysql
eg:-#mysql -u root -p321

mysql>create database ; <== to create database
eg:-mysql>create database salesdata;

mysql>show databases;
eg:-
+--------------------+
| Database |
+--------------------+
| information_schema |
| detail |
| mysql |
| salesdata |
| test |
+--------------------+

mysql>grant all privileges on .* to @'localhost' identified by '';<== to give the full acces to the user
eg:-mysql>grant all privileges on salesdata.* to raj@'localhost' identified by '1';<== grant command create new user also*

#mysql -u -p <== to login as a database user
eg:-#mysql -u raj -p salesdata

mysql>show databases; <== to list the tables in that particular database
eg:-
+-----------+
| Database |
+-----------+
| salesdata |
+-----------+

mysql>use ; <== to select a database
eg:-mysql>use salesdata;


mysql>show tables; <== to list the databases
eg:-
+---------------------+
| Tables_in_salesdata |
+---------------------+ <== It shows the tables in the salesdata database tables
| test |
+---------------------+
1 row in set (0.00 sec)

mysql> describe ; <== It describes the fields in test table
eg:-
+---------------+--------------+------+-----+------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+------------+----------------+
| num | int(11) | | PRI | NULL | auto_increment |
| date_modified | date | | MUL | 0000-00-00 | |
| name | varchar(50) | | MUL | | |
| description | varchar(75) | YES | | NULL | |
+---------------+--------------+------+-----+------------+----------------+

#mysqldump --database -u -p (db.name) > (db.name.sql) <== to take mysql backup (or) dump

eg:-mysqldump --database -u raj -p1 salesdata > salesdata.sql

#mysql -u raj -p1

mysql> drop database ; <== to drop a database
eg:-mysql> drop database salesdata;

#mysql -u raj -p1
mysql> create database ; <== to create a database again in the (same name)*
in other machine or etc..

# mysql --database -u -p (db.name) < (dbname.sql) <== to extract the database in the same name
eg:- mysql -u raj -p123 --database salesdata < salesdata.sql <== all the tables in the backup database will extracted
in this databse.
#mysql -u root -p123

#flush privileges; <== to change the privileges