microsoft windows [版本 6.1.7601]
版权所有 (c) 2009 microsoft corporation。保留所有权利。
c:/users/administrator>net start mysql56
mysql56 服务正在启动 ..
mysql56 服务已经启动成功。
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 |
+---------+----------+--------+
| 中签 | 职员 | 5000 |
| 公共 | 职员 | 4500 |
| 寝室 | 职员 | 3500 |
| 就是 | 职员 | 5500 |
| 张三 | 部门经理 | 8000 |
| 李四 | 职员 | 4000 |
| 李帅 | 职员 | 3000 |
| 李波 | 职员 | 3000 |
| 王五 | 职员 | 4000 |
| 高就 | 经理 | 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>