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. iOS:导航控制器侧滑出栈实现

    介绍:在iOS中,导航控制器UINavigationController是默认实现左侧边缘侧滑手势出栈的,但是如果当开发者对导航控制器子控制实现自定义leftBaButtonItem时,这个侧滑功能就 ...

  2. 取url中的参数值

    string url = "https://i.cnblogs.com/EditPosts.aspx?opt=1";//key不区分大小string key="opt&q ...

  3. scrapy-splash抓取动态数据例子五

    一.介绍 本例子用scrapy-splash抓取智能电视网网站给定关键字抓取咨询信息. 给定关键字:打通:融合:电视 抓取信息内如下: 1.资讯标题 2.资讯链接 3.资讯时间 4.资讯来源 二.网站 ...

  4. select()/poll() 的内核实现

    mark 引用:http://janfan.cn/chinese/2015/01/05/select-poll-impl-inside-the-kernel.html 文章 select()/poll ...

  5. 转: android sdk for mac

    转:http://www.cnblogs.com/yjmyzz/p/4219829.html 众所周知的原因,google的很多网站在国内无法访问,苦逼了一堆天朝程序员,下是在mac本上折腾andro ...

  6. LeetCode 137 Single Number II(仅仅出现一次的数字 II)(*)

    翻译 给定一个整型数组,除了某个元素外其余的均出现了三次. 找出这个元素. 备注: 你的算法应该是线性时间复杂度. 你能够不用额外的空间来实现它吗? 原文 Given an array of inte ...

  7. UITableViewCell 添加 checkbox 多选

    TableViewCell多选: CheckBox; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndex ...

  8. Activity生命周期以及启动模式对生命周期的影响(二)

    前面一篇文章概述了Android四大组件之一的Activity生命周期方法的调用先后顺序,但对于非标准启动模式下Activity被多次调用时的一些生命周期方法并未详细阐述,现在针对该情况着重记录. 现 ...

  9. js中求水仙花数

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Android自动化测试之MonkeyRunner录制和回放脚本

    Android自动化测试之MonkeyRunner录制和回放脚本(十一) 分类: 自动化测试 Android自动化 2013-02-22 10:57 7346人阅读 评论(2) 收藏 举报 andro ...