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. Java自定义注解基础知识

    注解分为三类:没有任何元素的注解,有一个元素的注解和有多个元素的注解. 1. Marker注解 这类注解没有任何元素,此类注解仅仅是一个标示.如下所示: public @interface Good ...

  2. win下idea远程提交WordCount任务到HA集群

    一,环境配置 1,修改win下的host文件:即C:\Windows\System32\drivers\etc\host中添加集群中机子的ip 2,win下hadoop,并为win的环境变量配置had ...

  3. Python Pygal绘制世界人口地图

    数据集可在 https://datahub.io/JohnSnowLabs/population-figures-by-country 下载 #coding=utf-8 import json fro ...

  4. 绿化和卸载 DOS 批处理

    @ECHO OFF&PUSHD %~DP0 &TITLE 绿化和选项 mode con cols= lines= color 2F Rd >NUL Md >NUL||(Ec ...

  5. [Angular] AfterContentChecked && AfterViewChecked

    AfterContentChecked & AfterViewChecked are called after 'OnChanges' lifecycle. And each time 'ng ...

  6. Node.js mm131图片批量下载爬虫1.00 iconv协助转码

    //====================================================== // mm131图片批量下载爬虫1.00 // 2017年11月15日 //===== ...

  7. Android avd XDM authorization key matches an existing client

    在启动 android avd 调试程序的时候,突然出现这个错误; XDM authorization key matches an existing client avd 怎么也启动不起来.网上搜也 ...

  8. 浅记初次使用expect、scp中出现的一些小问题

    以前也学过一些shell,不过学得并不是很深入,动手写的代码的时间也不是很多.前不久将shell比较细的过了一遍,leader布置了任务让用shell写一个脚本将redis源码压缩包从一个服务器上传到 ...

  9. ThinkPHP 3.2 中获取所有函数方法名,以及注释,完整可运行

    <?php namespace Home\Controller; use Common\Controller\BaseController; class AuthController exten ...

  10. winfrom 底层类 验证码

    效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzgxNjcwOQ==/font/5a6L5L2T/fontsize/400/fill/I ...