1. 连接mysql数据库:

输入:

mysql> mysql -uroot -p123(注意后面没有分号!!)

输出:

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 5.7.10-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

2. 查看所有数据库:

输入:

mysql> show databases;

输出:

+--------------------+
| Database |
+--------------------+
| information_schema |
| dedecms |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
6 rows in set (0.00 sec)

3. 创建数据库:

输入:

mysql> create database school;

显示:

Query OK, 1 row affected (0.03 sec)

4. 删除数据库:

输入:

mysql> drop database school;

输出:

Query OK, 0 rows affected (0.27 sec)

5. 进入某个数据库:

输入:

mysql> use test;

输出:

Database changed

6. 创建表:

输入:

(顺序为:字段名,数据类型(数据字节数),是否为空,是否为主键,自动增加,默认值。)

mysql> create table class(
-> id int(4) not null primary key auto_increment,
-> name char(20) not null,
-> sex int(4) not null default '0',
-> degree double(16,2));

输出:

Query OK, 0 rows affected (0.62 sec)

7. 向表中插入数据:

输入:

(insert into最好带上into;可同时插入多条数据,但是要对应。)

mysql> insert into class(name,degree) values('jia',98),('chen',76);

输出:

Query OK, 2 rows affected (0.08 sec)
Records: 2 Duplicates: 0 Warnings: 0

8. 查询表:

输入:

mysql> select * from class;

输出:

+----+------+-----+--------
| id | name | sex | degree
+----+------+-----+--------
| 1 | jia | 0 | 98.00
| 2 | chen | 0 | 76.00
+----+------+-----+--------
2 rows in set (0.00 sec)

9. 更改表中数据

输入:

mysql> update class set degree='100' where id = 2;

输出:

Query OK, 1 row affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 0

10. 删除表中数据

输入:

mysql> delete from class where id = 2;

输出:

Query OK, 1 row affected (0.45 sec)

11. 查看表结构

输入:

mysql> desc class;

(另外还有这几个:show columns from 表名;describe 表名;show create table 表名;)

输出:

+--------+--------------+------+-----+---------+----------------+
| Field     | Type            | Null    | Key |   Default | Extra               |
+--------+--------------+------+-----+---------+----------------+
| id         | int(4)          | NO     | PRI  | NULL      | auto_increment |
| name    | char(20)      | NO    |        | NULL      |                        |
| sex      | int(4)           | NO    |        | 0           |                        |
| degree | double(16,2) | YES   |       | NULL      |                        |
+--------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

12. 增加字段

输入:

mysql> alter table class add age int not null;

13. 删除字段

输入:

mysql> alter table class drop age;

14. 修改字段

输入:

mysql> alter table class change age sex int not null;

15. limit用法

输入:

mysql>SELECT * FROM users ORDER BY id LIMIT 5;

(选择前5行数据)

输入:

mysql>SELECT * FROM users ORDER BY id LIMIT 5,10;

(从第5行开始,选择10行数据)

PHP学习笔记(10)mysql常用命令的更多相关文章

  1. docker学习笔记二:常用命令

    docker学习笔记二:常用命令 查看docker常用命令 docker --help 返回结果如下: 其中常用的命令如下: 1.image相关操作 展示所有的image: 删除image: rmi ...

  2. linux学习笔记2-linux的常用命令

    第一篇博客:linux学习笔记1-ubuntu的安装与基本设置 之中,已经介绍了如何安装linux操作系统,以及一些基本的设置修改. 本篇博客主要介绍linux中的一些常用的终端命令 ======== ...

  3. linux学习笔记2 - linux常用命令

    转载请标注原链接:http://www.cnblogs.com/xczyd/p/5543731.html 第一篇博客:linux学习笔记1-ubuntu的安装与基本设置 之中,已经介绍了如何安装lin ...

  4. Oracle学习笔记—数据字典和常用命令(转载)

    转载自: oracle常用数据字典和SQL语句总结 Oracle常用命令大全(很有用,做笔记) 一.Oracle数据字典 数据字典是Oracle存放有关数据库信息的地方,其用途是用来描述数据的.比如一 ...

  5. ARM学习笔记10——GNU ARM命令行工具

    一.编译器arm-linux-gcc 1.用arm-linux-gcc编译一个程序,一般它是要经过如下步骤的: 1.1.预处理阶段 编译器把上述代码中stdio.h编译进来,使用GCC的选项-E可以使 ...

  6. 吴裕雄--天生自然MySQL学习笔记:MySQL ALTER命令

    需要修改数据表名或者修改数据表字段时,就需要使用到MySQL ALTER命令. root@host# mysql -u root -p password; Enter password:******* ...

  7. CMake学习笔记四-CMake常用命令

    CMake常用命令 PROJECT PROJECT(projectname [CXX] [C] [Java]) 指定工程名称,并可指定工程支持的语言.支持语言列表可忽略,默认支持所有语言 SET ...

  8. Linux学习笔记之六————Linux常用命令之系统管理

    <1>查看当前日历:cal cal命令用于查看当前日历,-y显示整年日历: <2>显示或设置时间:date 设置时间格式(需要管理员权限): date [MMDDhhmm[[C ...

  9. Linux学习笔记之五————Linux常用命令之用户、权限管理

    一.引言 用户是Unix/Linux系统工作中重要的一环,用户管理包括用户与组账号的管理. 在Unix/Linux系统中,不论是由本机或是远程登录系统,每个系统都必须拥有一个账号,并且对于不同的系统资 ...

  10. Linux学习笔记之四————Linux常用命令之文件管理

    Linux命令——文件管理相关命令 <1>查看文件信息:ls ls是英文单词list的简写,其功能为列出目录的内容,是用户最常用的命令之一,它类似于DOS下的dir命令. Linux文件或 ...

随机推荐

  1. [转]Insert, Update, and Delete Destination table with SSIS

    本文转自:http://www.rad.pasfu.com/index.php?/archives/150-Insert,-Update,-and-Delete-Destination-table-w ...

  2. [Python爬虫] Selenium +phantomjs 模拟下拉滚动条

    在爬虫中,有时会遇到这种情况,数据的展示是不是一页一页的,而是通过不断的下拉滚动条来加载数据.例如一点咨询(http://www.yidianzixun.com/)和微博(在未登录的状态下:http: ...

  3. Shiro(4)默认鉴权与自定义鉴权

    =========默认鉴权======== 过滤链中定义: <!-- 过滤链定义 --> <property name="filterChainDefinitions&qu ...

  4. 【笔记】关于require.js 的用法

    最近忙于学校的一个新网站建设,对于以前的前端程序编写方式的不正规特意上网学习了require.js 的用法,使此次的工程更加有条理同时符合当前前端的开发模式——前端模块化. 网上有不少很好的学习文章这 ...

  5. mac软件下载

    mac软件下载 http://www.pc6.com/mac/ https://www.macx.cn/

  6. Centos 7 通过yum的方式安装配置Artifactory 5.10

    制品仓库系统有很多,例如:Artifactory,Nexus,Archiva, 其中Artifactory拥有很多强大的企业级特性和人性化的用户接口,很多大型的公司都在使用它. 背景:因客户需求,需要 ...

  7. FEC

    什么是FEC http://zhidao.baidu.com/link?url=sbk7ue4n75HCbumrznBlAwdZAII8ZK2Xp3HTJ5BRkLJtDLFN3MGp9KOlrHVp ...

  8. 一直加载“fonts.googleapis.com”的解决办法

    原文:http://www.tuicool.com/articles/6bayeq 最近国内对google又开始了新一轮的屏蔽,很多wordpress用户发现一个现象,那就是网站前台和后台打开都非常慢 ...

  9. MYSQL AND OR的联用

    MYSQL中"AND"和"OR"都是条件控制符."AND"是求交集,而"OR"则是求并集,非常多情况下,须要联用它们两个 ...

  10. 一个漂亮而强大的RecyclerView

    代码地址如下:http://www.demodashi.com/demo/13470.html 简介 主要提供了简单易用强大的RecyclerView库,包括自定义刷新加载效果.极简通用的万能适配器A ...