MySql技术内幕之MySQL入门(2)

接上一篇。

mysql> source create_member.sql;  # 创建member表
Query OK, 0 rows affected, 1 warning (0.00 sec) Query OK, 0 rows affected (0.26 sec) mysql> source insert_member.sql; # 插入member表数据
Query OK, 0 rows affected (0.00 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.08 sec) Query OK, 1 row affected (0.08 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.08 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.06 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.06 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.28 sec) Query OK, 1 row affected (0.07 sec) Query OK, 1 row affected (0.06 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.06 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.14 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.06 sec) Query OK, 1 row affected (0.04 sec) Query OK, 1 row affected (0.05 sec) Query OK, 1 row affected (0.05 sec) mysql> SHOW TABLES; # 列出默认数据库中的表
+------------------+
| Tables_in_sampdb |
+------------------+
| member |
| president |
+------------------+
3 rows in set (0.00 sec) mysql> SHOW DATABASES; # 列出当前连接到服务器上的所有数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sampdb |
| sys |
+--------------------+
5 rows in set (0.00 sec)

美史联盟表

以上创建了两个表:president表和member表。

下面简单介绍一下这两张表

president表

mysql> DESC president;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| last_name | varchar(15) | NO | | NULL | |
| first_name | varchar(15) | NO | | NULL | |
| suffix | varchar(5) | YES | | NULL | |
| city | varchar(20) | NO | | NULL | |
| state | varchar(2) | NO | | NULL | |
| birth | date | NO | | NULL | |
| death | date | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)

姓名

出生地(城市和州)

出生日期

逝世日期

member表

mysql> DESC member;
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| member_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| last_name | varchar(20) | NO | | NULL | |
| first_name | varchar(20) | NO | | NULL | |
| suffix | varchar(5) | YES | | NULL | |
| expiration | date | YES | | NULL | |
| email | varchar(100) | YES | | NULL | |
| street | varchar(50) | YES | | NULL | |
| city | varchar(50) | YES | | NULL | |
| state | varchar(2) | YES | | NULL | |
| zip | varchar(10) | YES | | NULL | |
| phone | varchar(20) | YES | | NULL | |
| interests | varchar(255) | YES | | NULL | |
+------------+------------------+------+-----+---------+----------------+
12 rows in set (0.00 sec)

ID编号

姓名

有效期

电子邮件地址

通信地址

电话号码

兴趣爱好

检索信息

mysql> SELECT * FROM president; # 检索全部信息
+------------+---------------+--------+---------------------+-------+------------+------------+
| last_name | first_name | suffix | city | state | birth | death |
+------------+---------------+--------+---------------------+-------+------------+------------+
| Washington | George | NULL | Wakefield | VA | 1732-02-22 | 1799-12-14 |
| Adams | John | NULL | Braintree | MA | 1735-10-30 | 1826-07-04 |
| Jefferson | Thomas | NULL | Albemarle County | VA | 1743-04-13 | 1826-07-04 |
| Madison | James | NULL | Port Conway | VA | 1751-03-16 | 1836-06-28 |
| Monroe | James | NULL | Westmoreland County | VA | 1758-04-28 | 1831-07-04 |
| Adams | John Quincy | NULL | Braintree | MA | 1767-07-11 | 1848-02-23 |
| Jackson | Andrew | NULL | Waxhaw settlement | SC | 1767-03-15 | 1845-06-08 |
| Van Buren | Martin | NULL | Kinderhook | NY | 1782-12-05 | 1862-07-24 |
| Harrison | William H. | NULL | Berkeley | VA | 1773-02-09 | 1841-04-04 |
| Tyler | John | NULL | Greenway | VA | 1790-03-29 | 1862-01-18 |
| Polk | James K. | NULL | Pineville | NC | 1795-11-02 | 1849-06-15 |
| Taylor | Zachary | NULL | Orange County | VA | 1784-11-24 | 1850-07-09 |
| Fillmore | Millard | NULL | Locke | NY | 1800-01-07 | 1874-03-08 |
| Pierce | Franklin | NULL | Hillsboro | NH | 1804-11-23 | 1869-10-08 |
| Buchanan | James | NULL | Mercersburg | PA | 1791-04-23 | 1868-06-01 |
| Lincoln | Abraham | NULL | Hodgenville | KY | 1809-02-12 | 1865-04-15 |
| Johnson | Andrew | NULL | Raleigh | NC | 1808-12-29 | 1875-07-31 |
| Grant | Ulysses S. | NULL | Point Pleasant | OH | 1822-04-27 | 1885-07-23 |
| Hayes | Rutherford B. | NULL | Delaware | OH | 1822-10-04 | 1893-01-17 |
| Garfield | James A. | NULL | Orange | OH | 1831-11-19 | 1881-09-19 |
| Arthur | Chester A. | NULL | Fairfield | VT | 1829-10-05 | 1886-11-18 |
| Cleveland | Grover | NULL | Caldwell | NJ | 1837-03-18 | 1908-06-24 |
| Harrison | Benjamin | NULL | North Bend | OH | 1833-08-20 | 1901-03-13 |
| McKinley | William | NULL | Niles | OH | 1843-01-29 | 1901-09-14 |
| Roosevelt | Theodore | NULL | New York | NY | 1858-10-27 | 1919-01-06 |
| Taft | William H. | NULL | Cincinnati | OH | 1857-09-15 | 1930-03-08 |
| Wilson | Woodrow | NULL | Staunton | VA | 1856-12-19 | 1924-02-03 |
| Harding | Warren G. | NULL | Blooming Grove | OH | 1865-11-02 | 1923-08-02 |
| Coolidge | Calvin | NULL | Plymouth Notch | VT | 1872-07-04 | 1933-01-05 |
| Hoover | Herbert C. | NULL | West Branch | IA | 1874-08-10 | 1964-10-20 |
| Roosevelt | Franklin D. | NULL | Hyde Park | NY | 1882-01-30 | 1945-04-12 |
| Truman | Harry S | NULL | Lamar | MO | 1884-05-08 | 1972-12-26 |
| Eisenhower | Dwight D. | NULL | Denison | TX | 1890-10-14 | 1969-03-28 |
| Kennedy | John F. | NULL | Brookline | MA | 1917-05-29 | 1963-11-22 |
| Johnson | Lyndon B. | NULL | Stonewall | TX | 1908-08-27 | 1973-01-22 |
| Nixon | Richard M. | NULL | Yorba Linda | CA | 1913-01-09 | 1994-04-22 |
| Ford | Gerald R. | NULL | Omaha | NE | 1913-07-14 | 2006-12-26 |
| Carter | James E. | Jr. | Plains | GA | 1924-10-01 | NULL |
| Reagan | Ronald W. | NULL | Tampico | IL | 1911-02-06 | 2004-06-05 |
| Bush | George H.W. | NULL | Milton | MA | 1924-06-12 | NULL |
| Clinton | William J. | NULL | Hope | AR | 1946-08-19 | NULL |
| Bush | George W. | NULL | New Haven | CT | 1946-07-06 | NULL |
| Obama | Barack H. | NULL | Honolulu | HI | 1961-08-04 | NULL |
+------------+---------------+--------+---------------------+-------+------------+------------+
43 rows in set (0.00 sec) mysql> SELECT first_name FROM president; # 检索单个信息
+---------------+
| first_name |
+---------------+
| George |
| John |
| Thomas |
| James |
| James |
| John Quincy |
| Andrew |
| Martin |
| William H. |
| John |
| James K. |
| Zachary |
| Millard |
| Franklin |
| James |
| Abraham |
| Andrew |
| Ulysses S. |
| Rutherford B. |
| James A. |
| Chester A. |
| Grover |
| Benjamin |
| William |
| Theodore |
| William H. |
| Woodrow |
| Warren G. |
| Calvin |
| Herbert C. |
| Franklin D. |
| Harry S |
| Dwight D. |
| John F. |
| Lyndon B. |
| Richard M. |
| Gerald R. |
| James E. |
| Ronald W. |
| George H.W. |
| William J. |
| George W. |
| Barack H. |
+---------------+
43 rows in set (0.00 sec) mysql> SELECT first_name, last_name FROM president; # 检索多个信息
+---------------+------------+
| first_name | last_name |
+---------------+------------+
| George | Washington |
| John | Adams |
| Thomas | Jefferson |
| James | Madison |
| James | Monroe |
| John Quincy | Adams |
| Andrew | Jackson |
| Martin | Van Buren |
| William H. | Harrison |
| John | Tyler |
| James K. | Polk |
| Zachary | Taylor |
| Millard | Fillmore |
| Franklin | Pierce |
| James | Buchanan |
| Abraham | Lincoln |
| Andrew | Johnson |
| Ulysses S. | Grant |
| Rutherford B. | Hayes |
| James A. | Garfield |
| Chester A. | Arthur |
| Grover | Cleveland |
| Benjamin | Harrison |
| William | McKinley |
| Theodore | Roosevelt |
| William H. | Taft |
| Woodrow | Wilson |
| Warren G. | Harding |
| Calvin | Coolidge |
| Herbert C. | Hoover |
| Franklin D. | Roosevelt |
| Harry S | Truman |
| Dwight D. | Eisenhower |
| John F. | Kennedy |
| Lyndon B. | Johnson |
| Richard M. | Nixon |
| Gerald R. | Ford |
| James E. | Carter |
| Ronald W. | Reagan |
| George H.W. | Bush |
| William J. | Clinton |
| George W. | Bush |
| Barack H. | Obama |
+---------------+------------+
43 rows in set (0.00 sec)

指定检索条件

mysql> SELECT last_name, first_name FROM president
-> WHERE last_name = 'ROOSEVELT'; # 指定检索条件,last_name = 'ROOSEVELT'
+-----------+-------------+
| last_name | first_name |
+-----------+-------------+
| Roosevelt | Theodore |
| Roosevelt | Franklin D. |
+-----------+-------------+
2 rows in set (0.00 sec) mysql> SELECT last_name, first_name FROM president
-> WHERE last_name = 'roosevelt'; # 字符集通常不区分大小写
+-----------+-------------+
| last_name | first_name |
+-----------+-------------+
| Roosevelt | Theodore |
| Roosevelt | Franklin D. |
+-----------+-------------+
2 rows in set (0.00 sec)

MySql技术内幕之MySQL入门(2)的更多相关文章

  1. MySql技术内幕之MySQL入门(1)

    目录 MySql技术内幕之MySQL入门(1) 安装 关于注释 执行SQL语句 关于命令大小写 创建数据库 查看表的信息 查看更加详细的信息 查看与给定模式相匹配的列 插入数据 利用insert添加行 ...

  2. Mysql技术内幕(第四版)读书笔记(一)

    题记:写代码已经有2年了,学到了很多知识,但是没有一个好习惯去记录,去分享,好多知识点都会忘记,所以从今天开始学着像大牛一样去记录自己经历项目的点点滴滴,先从最近读<Mysql技术内幕>开 ...

  3. mysql技术内幕InnoDB存储引擎-阅读笔记

    mysql技术内幕InnoDB存储引擎这本书断断续续看了近10天左右,应该说作者有比较丰富的开发水平,在源码级别上分析的比较透彻.如果结合高可用mysql和高性能mysql来看或许效果会更好,可惜书太 ...

  4. 《MySQL技术内幕:InnoDB存储引擎(第2版)》书摘

    MySQL技术内幕:InnoDB存储引擎(第2版) 姜承尧 第1章 MySQL体系结构和存储引擎 >> 在上述例子中使用了mysqld_safe命令来启动数据库,当然启动MySQL实例的方 ...

  5. 《mysql技术内幕 InnoDB存储引擎(第二版)》阅读笔记

    一.mysql架构 mysql是一个单进程多线程架构的数据库. 二.存储引擎 InnoDB: 支持事务 行锁 读操作无锁 4种隔离级别,默认为repeatable 自适应hash索引 每张表的存储都是 ...

  6. Mysql技术内幕——InnoDB存储引擎

    Mysql技术内幕——InnoDB存储引擎 http://jingyan.baidu.com/article/fedf07377c493f35ac89770c.html 一.mysql体系结构和存储引 ...

  7. 《[MySQL技术内幕:SQL编程》读书笔记

    <[MySQL技术内幕:SQL编程>读书笔记 2019年3月31日23:12:11 严禁转载!!! <MySQL技术内幕:SQL编程>这本书是我比较喜欢的一位国内作者姜承尧, ...

  8. 读书笔记-《Mysql技术内幕》

    MYSQL 技术内幕 Mysql体系 连接池组件 管理服务和工具 SQL接口 查询分析器 优化器 缓冲 插件式存储引擎 物理文件 存储引擎 InnoDB(默认引擎) 支持事务 行锁设计 多版本并发控制 ...

  9. Mysql技术内幕之InnoDB锁探究

    自7月份换工作以来,期间一直在学习MySQL的相关知识,听了一些视频课,但是一直好奇那些讲师的知识是从哪里学习的.于是想着从书籍中找答案.毕竟一直 看视频也不是办法,不能形成自己的知识.于是想着看书汲 ...

随机推荐

  1. 201521123121 《Java程序设计》第10周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 进程:每个进程都有独立的代码和数据空间,进程间的切换会有较大的开销,一个进程包含1--n个线程. 线程:同一 ...

  2. 用户登陆注册【JDBC版】

    前言 在讲解Web开发模式的时候,曾经写过XML版的用户登陆注册案例!现在在原有的项目上,使用数据库版来完成用户的登陆注册!如果不了解的朋友,可以看看我Web开发模式的博文! 本来使用的是XML文件作 ...

  3. Hibernate第一篇【介绍Hibernate,简述ORM,快速入门】

    前言 前面已经学过了Struts2框架了,紧接着就是学习Hibernate框架了-本博文主要讲解介绍Hibernate框架,ORM的概念和Hibernate入门 什么是Hibernate框架? Hib ...

  4. springmvc02

    1,创建实体类对象User 注意要导入 bean-validator.jar 包 package com.yangw.springmvc.entity; import org.hibernate.va ...

  5. Struts2基于XML配置方式实现对Action方法进行校验

    JavaWeb框架(2)  使用XML对Action方法进行校验方式有两种,一种是对Action的所有方法进行校验,另一种是对Action指定方法进行校验. 对Action的所有方法进行校验: 步骤: ...

  6. Flask-WTF 创建表单P2

    表单安全 无需任何配置,FlaskForm将提供具有CSRF(Cross-site request forgery,也被称为one-click attack 或者session riding,通常缩写 ...

  7. Java开发中遇到的问题

    head丢失 html的dtd不对 Integer数据类型 使用==比较 这个肯定错(事后才知道) sql语句处理分组的时候,在本地服务使用没问题,在服务器上出现sql异常 group by语句规范, ...

  8. 语音传输之RTP/RTCP/UDP及软件实现关键点

    语音通信是实时通信,一定要保证实时性,不然用户体验会很糟糕.IETF设计了RTP来承载语音等实时性要求很高的数据,同时设计了RTCP来保证服务质量(RTP不保证服务质量).在传输层,一般选用UDP而不 ...

  9. Redis学习——Redis持久化之AOF备份方式保存数据

    新技术的出现一定是在老技术的基础之上,并且完善了老技术的某一些不足的地方,新技术和老技术就如同JAVA中的继承关系.子类(新技术)比父类(老技术)更加的强大! 在前面介绍了Redis学习--Redis ...

  10. Collecting Bugs poj2096 概率DP

                                                                Collecting Bugs Time Limit: 10000MS   Me ...