By Below Method If Password Is Pass and User Name Is Root # (Mysql Dir) /bin/mysql - H Hostname - U Root - P Pass
By Below Method If Password Is Pass and User Name Is Root # (Mysql Dir) /bin/mysql - H Hostname - U Root - P Pass
5
Ques
How to see table's field formats or
tions
description of table .
:6
Answ
ers : mysql> describe tablename;
6
Ques
How to delete a database from mysql
tions
server.
:7
Answ
ers : mysql> drop database databasename;
7
Ques
tions How we get Sum of column
:8
Answ
ers : mysql> SELECT SUM(*) FROM [table name];
8
Ques
tions How to delete a table
:9
Answ
ers : mysql> drop table tablename;
9
Ques
tions How you will Show all data from a table.
: 10
Answ
ers : mysql> SELECT * FROM tablename;
10
Ques How to returns the columns and column
tions information pertaining to the designated
: 11 table
Answ
ers : mysql> show columns from tablename;
11
Ques
How to Show certain selected rows with
tions
the value "pcds"
: 12
Answ
mysql> SELECT * FROM tablename WHERE
ers :
fieldname = "pcds";
12
Ques How will Show all records containing the
tions name "sonia" AND the phone number
: 13 '9876543210'
Answ mysql> SELECT * FROM tablename WHERE
ers : name = "sonia" AND phone_number =
13
'9876543210';
Ques How you will Show all records not
tions containing the name "sonia" AND the
: 14 phone number '9876543210' order by the
phone_number field.
Answ mysql> SELECT * FROM tablename WHERE
er :
name != "sonia" AND phone_number =
14
'9876543210' order by phone_number;
Ques How to Show all records starting with the
Ques
tions how to Return total number of rows.
: 19
Answ
ers : mysql> SELECT COUNT(*) FROM tablename;
19
Ques
tions How to Join tables on common columns.
: 20
Answ mysql> select lookup.illustrationid,
er :
lookup.personid,person.birthday from lookup
20
left join person on
lookup.personid=person.personid=statement to
join birthday in person table with primary
illustration id
Ques How to Creating a new user. Login as root.
tions Switch to the MySQL db. Make the user.
: 21 Update privs.
Answ # mysql -u root -p
er :
21
mysql> use mysql;
mysql> INSERT INTO user
(Host,User,Password)
VALUES('%','username',PASSWORD('password')
);
mysql> flush privileges;
Ques
How to Change a users password from
tions
unix shell.
: 22
Answ
# [mysql dir]/bin/mysqladmin -u username -h
ers :
hostname.blah.org -p password 'new-password'
22
Ques How to Change a users password from
tions MySQL prompt. Login as root. Set the
: 23 password. Update privs.
Answ # mysql -u root -p
er :
23
mysql> SET PASSWORD FOR 'user'@'hostname'
= PASSWORD('passwordhere');
mysql> flush privileges;
Ques How to Recover a MySQL root password.
tions Stop the MySQL server process. Start again
: 24 with no grant tables. Login to MySQL as
root. Set new password. Exit MySQL and
restart MySQL server.
Answ # /etc/init.d/mysql stop
er :
# mysqld_safe --skip-grant-tables &
24
# mysql -u root
mysql> use mysql;
mysql> update user set
password=PASSWORD("newrootpassword")
where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
Ques How to Set a root password if there is on
tions
root password.
: 25
Answ
er :
# mysqladmin -u root password newpassword
25
Ques
tions How to Update a root password.
: 26
Answ
# mysqladmin -u root -p oldpassword
er :
newpassword
26
Ques How to allow the user "sonia" to connect
tions to the server from localhost using the
: 27 password "passwd". Login as root. Switch
to the MySQL db. Give privs. Update privs.
Answ # mysql -u root -p
ers : mysql> use mysql;
27
mysql> grant usage on *.* to sonia@localhost
identified by 'passwd';
mysql> flush privileges;
Ques How to give user privilages for a db. Login
tions as root. Switch to the MySQL db. Grant
: 28 privs. Update privs.
Answ # mysql -u root -p
ers : mysql> use mysql;
28
mysql> INSERT INTO user
(Host,Db,User,Select_priv,Insert_priv,Update_pr
iv,Delete_priv,Create_priv,Drop_priv) VALUES
('%','databasename','username','Y','Y','Y','Y','Y',
'N');
mysql> flush privileges;
or
tions
: 37
Answ # [mysql dir]/bin/mysqldump -c -u username
er :
-ppassword databasename tablename >
37
/tmp/databasename.tablename.sql
Ques
Restore database (or database table) from
tions
backup.
: 38
Answ # [mysql dir]/bin/mysql -u username
er :
-ppassword databasename <
38
/tmp/databasename.sql
Ques
tions How to Create Table show Example
: 39
Answ mysql> CREATE TABLE [table name] (firstname
er :
VARCHAR(20), middleinitial VARCHAR(3),
39
lastname VARCHAR(35),suffix
VARCHAR(3),officeid VARCHAR(10),userid
VARCHAR(15),username VARCHAR(8),email
VARCHAR(35),phone VARCHAR(25), groups
VARCHAR(15),datestamp DATE,timestamp
time,pgpemail VARCHAR(255));
Ques How to search second maximum(second
tions highest) salary value(integer)from table
: 40 employee (field salary)in the manner so
that mysql gets less load?
Answ
ers : By below query we will get second
maximum(second highest) salary
40
value(integer)from table employee (field
salary)in the manner so that mysql gets less
load?
SELECT DISTINCT(salary) FROM employee