zoukankan      html  css  js  c++  java
  • 程序媛计划——mysql基本操作

    本文适用于mac

    在官网上下载community 版mysql,选择dmy这种。在终端中安装好mysql。

    #进入mysql

     /usr/local/mysql/bin/mysql -uroot -p

    #修改root密码(root是默认的用户名)

    #账户名默认都是root,注意输入账户和新密码时不需要再带' '号

    [mysql> set password for ACCOUNT@localhost = password(NEW_PASSWORD);

    #直接敲 exit 退出mysql

    创建数据库、创建表

    #创建名为test的数据库

    mysql> create database test;
    #Query OK, 1 row affected (0.01 sec)

    #查看当前所有数据库

    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    | test               |
    +--------------------+
    5 rows in set (0.02 sec)

    #删除某数据库

    mysql> drop database test;
    #Query OK, 0 rows affected (0.01 sec)

    #查看当前数据库

    mysql> select database();
    +------------+
    | database() |
    +------------+
    | test       |
    +------------+
    1 row in set (0.00 sec)

    #对数据表进行操作

    #连接到数据库test
    [mysql> use test; Database changed
    #创建表
    #表中的各个列组成了一个元组 mysql
    > create table if not exists exam_score( -> id int(4) not null primary key auto_increment, #auto_increment自增 -> name char(20) not null, -> score double); Query OK, 0 rows affected (0.03 sec) #显示表的结构(各个列都有些啥属性) mysql> show columns from exam_score; +-------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+----------------+ | id | int(4) | NO | PRI | NULL | auto_increment | | name | char(20) | NO | | NULL | | | score | double | YES | | NULL | | +-------+----------+------+-----+---------+----------------+ 3 rows in set (0.01 sec) #展示所有表 mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | exam_score | +----------------+ 1 row in set (0.00 sec) #删除表(注意mysql中删除表和删除数据库都是drop,sqlite中删除表用delete) mysql> drop table exam_score; Query OK, 0 rows affected (0.00 sec)
    
    
  • 相关阅读:
    「CF722E Research Rover」
    「Luogu P4062 [Code+#1]Yazid 的新生舞会」
    【cf比赛记录】Codeforces Round #613 (Div. 2)
    【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)
    【cf补题记录】Codeforces Round #608 (Div. 2)
    【cf补题记录】Codeforces Round #607 (Div. 2)
    【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)
    【cf比赛记录】Codeforces Round #605 (Div. 3)
    【Codeforces】B. Div Times Mod
    【牛客练习赛53】A-超越学姐爱字符串
  • 原文地址:https://www.cnblogs.com/IcarusYu/p/7495125.html
Copyright © 2011-2022 走看看