• mysql


    1. 登录mysql

    mysql -u root -p   然后输入密码
    2, 查看已有数据库
    mysql> show databases;
    +--------------------+
    | Database                |
    +--------------------+
    | information_schema |
    | codeigniter        |
    | mysql              |
    | spam               |
    | test               |
    +--------------------+
    然后进入一个数据库:
    mysql> use test
    Database changed
    现在就进入test数据库了,然后显示这个数据库中的所有表:
    mysql> show tables;
    +-----------------------+
    | Tables_in_codeigniter |
    +-----------------------+
    | bey_sessions          |
    | migrations            |
    | problems              |
    | replies               |
    | solutions             |
    | tokens                |
    | topics                |
    | userinfos             |
    | users                 |
    | vips                  |
    +-----------------------+
    10 rows in set (0.00 sec)
    查看表的数据结构:
    mysql> desc users;
    +----------+------------------------+------+-----+---------+----------------+
    | Field    | Type                   | Null | Key | Default | Extra          |
    +----------+------------------------+------+-----+---------+----------------+
    | id       | mediumint(11) unsigned | NO   | PRI | NULL    | auto_increment |
    | username | varchar(100)           | NO   |     | NULL    |                |
    | password | varchar(80)            | NO   |     | NULL    |                |
    | email    | varchar(100)           | YES  |     | NULL    |                |
    | status   | tinyint(1) unsigned    | NO   |     | 0       |                |
    +----------+------------------------+------+-----+---------+----------------+
    3. 插入一条记录;
    mysql> insert into users values(null, 'ceshiyonghu', '111', '110000@qq.com', '1');
    Query OK, 1 row affected (0.01 sec)
    插入某个字段
    mysql> insert into users (id, username) values (null, 'liu');  
    Query OK, 1 row affected, 1 warning (0.00 sec)
    4. 查询记录:
    mysql> select * from users;
    +-------+-------------+------------------------------------------------------------------+---------------+--------+
    | id    | username    | password                                                         | email         | status |
    +-------+-------------+------------------------------------------------------------------+---------------+--------+
    | 10005 | ??134       | ccb797aae770710012a7b0e5834e7ee5c1994f80a31bc86332b96e1c90015cea | 0             |      0 |
    | 10006 | ????        | 31ed43c7ba20fa7b2600b200b064de3c7cdbafe0c32019101daf93203c8ac27b | NULL          |      0 |
    | 10007 | ceshiyonghu | 111                                                              | 110000@qq.com |      1 |
    | 10008 | liu         |                                                                  | NULL          |      0 |
    +-------+-------------+------------------------------------------------------------------+---------------+--------+
    查询某个字段
    mysql> select id, username from users;
    +-------+-------------+
    | id    | username    |
    +-------+-------------+
    | 10005 | ??134       |
    | 10006 | ????        |
    | 10007 | ceshiyonghu |
    | 10008 | liu         |
    +-------+-------------+
    4 rows in set (0.00 sec)
    5. 更新某个字段
    mysql> update users set username = 'liu2' where id = 10008;
    Query OK, 1 row affected (0.00 sec)
    where语句用来定位某几行
    mysql> select * from users;
    +-------+-------------+------------------------------------------------------------------+---------------+--------+
    | id    | username    | password                                                         | email         | status |
    +-------+-------------+------------------------------------------------------------------+---------------+--------+
    | 10005 | ??134       | ccb797aae770710012a7b0e5834e7ee5c1994f80a31bc86332b96e1c90015cea | 0             |      0 |
    | 10006 | ????        | 31ed43c7ba20fa7b2600b200b064de3c7cdbafe0c32019101daf93203c8ac27b | NULL          |      0 |
    | 10007 | ceshiyonghu | 111                                                              | 110000@qq.com |      1 |
    | 10008 | liu2        |                                                                  | NULL          |      0 |
    +-------+-------------+------------------------------------------------------------------
    更新多个字段
    mysql> update users set username = 'liu2' , password = '222' where id = 10008;  
    Query OK, 1 row affected (0.00 sec)
    mysql> select * from users;
    +-------+-------------+------------------------------------------------------------------+---------------+--------+
    | id    | username    | password                                                         | email         | status |
    +-------+-------------+------------------------------------------------------------------+---------------+--------+
    | 10005 | ??134       | ccb797aae770710012a7b0e5834e7ee5c1994f80a31bc86332b96e1c90015cea | 0             |      0 |
    | 10006 | ????        | 31ed43c7ba20fa7b2600b200b064de3c7cdbafe0c32019101daf93203c8ac27b | NULL          |      0 |
    | 10007 | ceshiyonghu | 111                                                              | 110000@qq.com |      1 |
    | 10008 | liu2        | 222                                                              | NULL          |      0 |
    +-------+-------------+------------------------------------------------------------------+---------------+--------+
    6. 删除记录:
    mysql> delete from users where id = 10008;
    Query OK, 1 row affected (0.00 sec)
    mysql> select * from users;              
    +-------+-------------+------------------------------------------------------------------+---------------+--------+
    | id    | username    | password                                                         | email         | status |
    +-------+-------------+------------------------------------------------------------------+---------------+--------+
    | 10005 | ??134       | ccb797aae770710012a7b0e5834e7ee5c1994f80a31bc86332b96e1c90015cea | 0             |      0 |
    | 10006 | ????        | 31ed43c7ba20fa7b2600b200b064de3c7cdbafe0c32019101daf93203c8ac27b | NULL          |      0 |
    | 10007 | ceshiyonghu | 111                                                              | 110000@qq.com |      1 |
    +-------+-------------+------------------------------------------------------------------+---------------+--------+

  • 相关阅读:
    在C#中使用SQL存储过程说明
    asp.net后台获取html控件值
    SQL字符串操作汇总[记住这个]select substring(quantityperunit,charindex('',quantityperunit)+1,100) as 结果 from products
    分页控件AspnetPager的用法,巩固用
    摆脱Access在.net中中模糊查询,老错的困扰
    基于黑金开发板的秒表verilog hdl程序
    2808 sci 接收中断
    黑金开发板状态机实现的可用按键控制的流水灯
    基于黑金开发板的键盘边沿检测程序
    可以使用键盘实现加减数的数码管的verilog hdl程序(基于黑金开发板)
  • 原文地址:https://www.cnblogs.com/liuhong/p/3378331.html
Copyright © 2020-2023  润新知