0

0

mysql常用命令案例_MySQL

php中文网

php中文网

发布时间:2016-06-01 13:10:12

|

1108人浏览过

|

来源于php中文网

原创

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)


免费红色响应式多语言企业通用模板1.0.0
免费红色响应式多语言企业通用模板1.0.0

该模板源码有公司简介、公司新闻、产品展示、客户案例、留言等企业官网常用页面功能。模板是响应式模板,支持多语言,完善的标签调用修改起来很方便。功能特点:1. 使用的框架采用HkCms开源内容管理系统v2.2.3版本、免费可以商用。2. 所需环境Apache/Nginx,PHP7.2 及以上 + MySQL 5.6 及以上。3. 安装教程: (1) 站点运行路径填写到public目录下。 (2) 浏览

下载

mysql>

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
php源码安装教程大全
php源码安装教程大全

本专题整合了php源码安装教程,阅读专题下面的文章了解更多详细内容。

65

2025.12.31

php网站源码教程大全
php网站源码教程大全

本专题整合了php网站源码相关教程,阅读专题下面的文章了解更多详细内容。

43

2025.12.31

视频文件格式
视频文件格式

本专题整合了视频文件格式相关内容,阅读专题下面的文章了解更多详细内容。

35

2025.12.31

不受国内限制的浏览器大全
不受国内限制的浏览器大全

想找真正自由、无限制的上网体验?本合集精选2025年最开放、隐私强、访问无阻的浏览器App,涵盖Tor、Brave、Via、X浏览器、Mullvad等高自由度工具。支持自定义搜索引擎、广告拦截、隐身模式及全球网站无障碍访问,部分更具备防追踪、去谷歌化、双内核切换等高级功能。无论日常浏览、隐私保护还是突破地域限制,总有一款适合你!

41

2025.12.31

出现404解决方法大全
出现404解决方法大全

本专题整合了404错误解决方法大全,阅读专题下面的文章了解更多详细内容。

204

2025.12.31

html5怎么播放视频
html5怎么播放视频

想让网页流畅播放视频?本合集详解HTML5视频播放核心方法!涵盖<video>标签基础用法、多格式兼容(MP4/WebM/OGV)、自定义播放控件、响应式适配及常见浏览器兼容问题解决方案。无需插件,纯前端实现高清视频嵌入,助你快速打造现代化网页视频体验。

9

2025.12.31

关闭win10系统自动更新教程大全
关闭win10系统自动更新教程大全

本专题整合了关闭win10系统自动更新教程大全,阅读专题下面的文章了解更多详细内容。

8

2025.12.31

阻止电脑自动安装软件教程
阻止电脑自动安装软件教程

本专题整合了阻止电脑自动安装软件教程,阅读专题下面的文章了解更多详细教程。

3

2025.12.31

html5怎么使用
html5怎么使用

想快速上手HTML5开发?本合集为你整理最实用的HTML5使用指南!涵盖HTML5基础语法、主流框架(如Bootstrap、Vue、React)集成方法,以及无需安装、直接在线编辑运行的平台推荐(如CodePen、JSFiddle)。无论你是新手还是进阶开发者,都能轻松掌握HTML5网页制作、响应式布局与交互功能开发,零配置开启高效前端编程之旅!

2

2025.12.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号