12-05-2012, 05:33 PM
SQL PROGRAMS
SQL PROGRAMS.doc (Size: 60.5 KB / Downloads: 35)
administrator@ubuntu:~$ sudo –s
[sudo] password for administrator:
root@ubuntu:~# mysql –p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> help
For information about MySQL products and services, visit: http://www.mysql
For developer information, including the MySQL Reference Manual, visit: http://dev.mysql
To buy MySQL Enterprise support, training, or other products, visit: https://shop.mysql
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
For server side help, type ' help contents '
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2012-01-03 00:37:08 |
+---------------------+
1 row in set (0.00 sec)
mysql> create database cse;
Query OK, 1 row affected (0.00 sec)
mysql> use cse;
Database changed
mysql> create table cse1(ss varchar(10),sss varchar(10));
Query OK, 0 rows affected (0.00 sec)
mysql> insert into cse1(ss,sss) values('z','xxx');
Query OK, 1 row affected (0.00 sec)
mysql> insert into cse1(ss,sss) values('zzz','yyy');
Query OK, 1 row affected (0.00 sec)
mysql> select * from cse1;
+------+------+
| ss | sss |
+------+------+
| z | xxx |
| zzz | yyy |
+------+------+
2 rows in set (0.00 sec)
mysql> select database();
+------------+
| database() |
+------------+
| cse |
+------------+
1 row in set (0.00 sec)
mysql> \s
--------------
mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (i486) using readline 6.1
Connection id: 37
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Client characterset: latin1
Server characterset: latin1
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 36 min 40 sec
Threads: 1 Questions: 131 Slow queries: 0 Opens: 113 Flush tables: 1 Open tables: 27 Queries per second avg: 0.59
--------------
mysql> select * from cse1 order by ss desc;
+------+------+
| ss | sss |
+------+------+
| zzz | yyy |
| z | xxx |
+------+------+
2 rows in set (0.00 sec)
mysql> select * from cse1 order by ss;
+------+------+
| ss | sss |
+------+------+
| z | xxx |
| zzz | yyy |
+------+------+
2 rows in set (0.00 sec)
mysql> delete from cse1 where ss='z';
Query OK, 1 row affected (0.00 sec)
mysql> select * from cse1;
+------+------+
| ss | sss |
+------+------+
| zzz | yyy |
+------+------+
1 row in set (0.00 sec)
mysql> insert into cse1(ss,sss) values('ccc','aaa');
Query OK, 1 row affected (0.00 sec)
mysql> insert into cse1(ss,sss) values('aaa','ccc');
Query OK, 1 row affected (0.00 sec)
mysql> insert into cse1(ss,sss) values('bbb','vvv');
Query OK, 1 row affected (0.00 sec)
mysql> CREATE DATABASE time_val;
Query OK, 1 row affected (0.01 sec)
mysql> USE time_val;
Database changed
mysql> CREATE TABLE time(t1 DATE, t2 TIME ,dt DATETIME, ts TIMESTAMP);
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM time;
Empty set (0.00 sec
mysql> INSERT INTO time (t1,t2,dt,ts) VALUES (02042011,015527,02042011015527,02042011015527);
Query OK, 1 row affected, 3 warnings (0.00 sec)
mysql> SELECT * FROM time;
+------------+----------+---------------------+---------------------+
| t1 | t2 | dt | ts |
+------------+----------+---------------------+---------------------+
| 0000-00-00 | 01:55:27 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
+------------+----------+---------------------+---------------------+
1 row in set (0.00 sec)
mysql> INSERT INTO time(t1,t2,dt,ts)VALUES(20110402,015527,20110402015527,20110402015527);
Query OK, 1 row affected (0.00 sec)