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. 二十四种设计模式:命令模式(Command Pattern)

    命令模式(Command Pattern) 介绍将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化:对请求排队或记录请求日志,以及支持可取消的操作. 示例有一个Message实体类,某个 ...

  2. [转]SSIS OLE DB Source中执行带参数的存储过程

    本文转自:http://www.cnblogs.com/michaelxu/archive/2009/10/21/1587450.html 问题描述:执行一个存储过程得到一个多条记录的结果集,然后循环 ...

  3. Linux now!--网络配置

    第一种:使用命令修改(直接即时生效,重启失效) #ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up 说明: eth0是第一个网卡,其他依次为eth1 ...

  4. python安装包是出现错误解决

    /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h:168:61: fatal error: limits.h: No such file ...

  5. Mapreduce报错:java.lang.ClassNotFoundException: Class Mapper not found

    mapreduce找不到mapper类 解决方法: 开始自己用的是mapreduce自己打包的一种方法: job.setJarByClass(StandardJob.class); 但这样一直在报错: ...

  6. [ES6] 09. Destructuring Assignment -- 2

    Read More: http://es6.ruanyifeng.com/#docs/destructuring Array “模式匹配”,只要等号两边的模式相同,左边的变量就会被赋予对应的值: Ex ...

  7. Tomcat性能调整完整教程

    Tomcat性能调整完整教程 发表于:2007-07-13来源:作者:点击数:526 标签: 一. 引言 性能测试与分析是软件 开发 过程中介于架构和调整的一个广泛并比较不容易理解的领域,更是一项较为 ...

  8. PHP安全:如何正确的取得使用者 IP?

    PHP安全:如何正确的取得使用者 IP? 很多网站都会有侦测用户 IP 的功能,不管是判断使用者来自哪边,或者是记录用户的位置.但是你知道吗?网络上大多数的教学全部都是「错误」的.正确的程序写法可以确 ...

  9. ubuntu错误解决E: Sub-process /usr/bin/dpkg returned an error code (1)

    在用apt-get安装软件时出现了类似于 install-info: No dir file specified; try –help for more information.dpkg:处理 get ...

  10. Linux下SVN部署/安全及权限配置,实现web同步更新

    转自:http://www.cnblogs.com/me115/archive/2013/04/07/3002058.html 本文包含以下内容: SVN服务器安装 SVN权限管理 SVN使用SASL ...