• mysql、MariaDB的简单操作


    mysql的简单操作

    一、查看数据库

    SHOW DATABASES;
    例如:
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | test |
    +--------------------+
    4 rows in set (0.00 sec)

    二、创建数据库

    CREATE DATABASE 数据库名称;
    例如:
    MariaDB [mysql]> create database han;
    Query OK, 1 row affected (0.01 sec)
     
    MariaDB [mysql]> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | han |
    | mysql |
    | performance_schema |
    | test |
    +--------------------+
    5 rows in set (0.00 sec)
     
     

    三、进入数据库

    USE 数据库名称;
    例如:
    MariaDB [mysql]> use han;
    Database changed

    四、查看表

    SHOW TABLES;
    例如:
    MariaDB [han]> show tables;
    +---------------+
    | Tables_in_han |
    +---------------+
    | redhat |
    +---------------+
    1 row in set (0.00 sec)
     

    五、新建数据表

    CREATE TABLE 数据表名称(
    ->列名称1 数据类型 not null,
    ->列名称2 数据类型 not null,
    . . . ,
    . . . ,
    . . .
    ->);
    MariaDB [han]> create table redhat(
    -> user varchar(50) not null,
    -> passwd varchar(50) not null
    -> );
    Query OK, 0 rows affected (0.02 sec)
     

    六、查看数据表内容

    SELECT * FORM 表名称;
    例如:
    MariaDB [han]> select * from redhat;
    +------+--------+
    | user | passwd |
    +------+--------+
    | user | 123 |
    +------+--------+
    1 row in set (0.00 sec)
     

    七、表中添加数据

    INSERT INTO 表名称 VALUES(‘第一列数据’,‘第二列数据’);
    例如:
    MariaDB [han]> insert into redhat values('user','123')
    -> ;
    Query OK, 1 row affected (0.00 sec)
     

    八、删除表中数据

    DELETE FROM 表名称 WHERE 列名=‘数据’;
    例如:
    MariaDB [han]> select * from redhat;
    +------+--------+
    | user | passwd |
    +------+--------+
    1 row in set (0.00 sec)
     

    九、删除表

    DROP TABLE 表名称;
    例如:
    MariaDB [han]> drop table redhat
    -> ;
    Query OK, 0 rows affected (0.01 sec)
     

    十、删除数据库

    DROP DATABASE 数据库名称;
    例如:
    MariaDB [han]> drop database han;
    Query OK, 0 rows affected (0.05 sec)
     
  • 相关阅读:
    河南省第十届ACM省赛G:Plumbing the depth of lake
    南洋理工oj 题目92 图像有用区域
    初学欧拉图,知识总结,后续增加
    初学并查集知识总结后续增加
    南阳oj 题目42 一笔画问题
    南阳oj 题目 90 整数划分
    南阳oj题目20吝啬的国度 菜鸟的进阶之路
    南阳oj 题目21 三个水杯
    UVA-540 Team Queue
    HDU-1596 find the safest road
  • 原文地址:https://www.cnblogs.com/majinhai/p/9425433.html
Copyright © 2020-2023  润新知