Mysql common command case _ MySQL

Source: Internet
Author: User
Mysql common command cases Microsoft Windows [version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:/Users/Administrator> net start mysql56
MySQL56 service is starting ..
The MySQL56 service has been started successfully.


C:/Users/Administrator> mysql-u root-p
Enter password :*****
Welcome to the MySQL monitor. Commands end with; or/g.
Your MySQL connection id is 1
Server version: 5.6.10 MySQL Community Server (GPL)

Type 'help; 'or'/h' for help. type'/C' to clear the buffer.

Mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Bbs |
| Book |
| Connect |
| Db_bbs |
| Db_database25 |
| Dreamtimenews |
| Hibernate |
| Hrsystem |
| Jeebbs |
| Jeecmsv5 |
| Meiupic |
| Mysql |
| News |
| Nmsdb |
| Oscommerce |
| Performance_schema |
| Sakila |
| Test |
| Vote |
| World |
+ -------------------- +
21 rows in set (0.23 sec)

Mysql> use test;
Database changed
Mysql> show tables;
+ ---------------- +
| Tables_in_test |
+ ---------------- +
| Employees |
| Student |
+ ---------------- +
2 rows in set (0.00 sec)

Mysql> select * from employees;
+ --------- + ---------- + -------- +
| Empname | title | salary |
+ --------- + ---------- + -------- +
| Signature | employee | 5000 |
| Public | employee | 4500 |
| Dormitory | employee | 3500 |
| Yes | employee | 5500 |
| James | department manager | 8000 |
| Li Si | employee | 4000 |
| Li Shuai | employee | 3000 |
| Li Bo | employee | 3000 |
| Wang Wu | employee | 4000 |
| Senior manager | 6000 |
+ --------- + ---------- + -------- +
10 rows in set (0.10 sec)

Mysql> create table persons
-> (
-> Id int not null,
-> Name varchar (20 ),
-> Mgrid varchar (20)
-> );
Query OK, 0 rows affected (0.11 sec)


Mysql> insert into persons (id, name) values (1, 'zwh1 ');
Query OK, 1 row affected (0.01 sec)

Mysql> insert into persons (id, name) values (2, 'zwh2 ');
Query OK, 1 row affected (0.00 sec)

Mysql> alter table persons
-> Modify column mgrid
-> Int;
Query OK, 2 rows affected (0.07 sec)
Records: 2 Duplicates: 0 Warnings: 0

Mysql> desc persons;
+ ------- + ------------- + ------ + ----- + --------- + ------- +
| Field | Type | Null | Key | Default | Extra |
+ ------- + ------------- + ------ + ----- + --------- + ------- +
| Id | int (11) | NO | NULL |
| Name | varchar (20) | YES | NULL |
| Mgrid | int (11) | YES | NULL |
+ ------- + ------------- + ------ + ----- + --------- + ------- +
3 rows in set (0.06 sec)

Mysql> select * from persons;
+ ---- + ------ + ------- +
| Id | name | mgrid |
+ ---- + ------ + ------- +
| 1 | zwh1 | NULL |
| 2 | zwh2 | NULL |
+ ---- + ------ + ------- +
2 rows in set (0.00 sec)

Mysql> insert into persons (id, name, mgrid) values (2, 'zwh2', '1 ');
Query OK, 1 row affected (0.00 sec)

Mysql> insert into persons (id, name, mgrid) values (4, 'zwh4', '2 ');
Query OK, 1 row affected (0.00 sec)

Mysql> select * from persons;
+ ---- + ------ + ------- +
| Id | name | mgrid |
+ ---- + ------ + ------- +
| 1 | zwh1 | NULL |
| 2 | zwh2 | NULL |
| 2 | zwh2 | 1 |
| 4 | zwh4 | 2 |
+ ---- + ------ + ------- +
4 rows in set (0.00 sec)

Mysql> update persons set id = 3 where mgrid = 1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Mysql> update persons set name = 'zwh3' where mgrid = 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Mysql> select * from persons;
+ ---- + ------ + ------- +
| Id | name | mgrid |
+ ---- + ------ + ------- +
| 1 | zwh1 | NULL |
| 2 | zwh2 | NULL |
| 3 | zwh3 | 1 |
| 4 | zwh4 | 2 |
+ ---- + ------ + ------- +
4 rows in set (0.00 sec)

Mysql> select id, name, person2.mgrid, person2.name as mgrname
-> From persons inner join persons as person2
-> On persons. id = person2.mgrid;
ERROR 1052 (23000): Column 'id' in field list is ambiguous
Mysql> select persons. id, persons. name, person2.mgrid, person2.name as mgrname
-> From persons inner join persons as person2
-> On persons. id = person2.mgrid;
+ ---- + ------ + ------- + --------- +
| Id | name | mgrid | mgrname |
+ ---- + ------ + ------- + --------- +
| 1 | zwh1 | 1 | zwh3 |
| 2 | zwh2 | 2 | zwh4 |
+ ---- + ------ + ------- + --------- +

2 rows in set (0.03 sec)

Mysql> select persons. id as mgrid, persons. name as mgrname, person2.id, person2.name
-> From persons inner join persons as person2
-> On persons. id = person2.mgrid;
+ ------- + --------- + ---- + ------ +
| Mgrid | mgrname | id | name |
+ ------- + --------- + ---- + ------ +
| 1 | zwh1 | 3 | zwh3 |
| 2 | zwh2 | 4 | zwh4 |
+ ------- + --------- + ---- + ------ +
2 rows in set (0.00 sec)



Mysql>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.