【MySQL】MySQL基础01 — 初识MySQL(转载请注明出处)

MySQL基础 — 初识MySQL

一、为什么要学习数据库

  • 能够实现数据持久化
  • 使用完整的管理系统统一管理,易于查询

二、数据库相关概念

DB

数据库(database),存储数据的“仓库”,保存了一系列有组织的数据

DBMS

数据库管理系统(Database Management System),DB是通过DBMS创建和操作的容器。常见的DBMS有:MySQL \ Oracle \ DB2 \ SQL Server

  • 分类:
    1. 基于共享文件系统的DBMS:微软(Access)
    2. 基于客户机——服务器(C/S)的DBMS:甲骨文(MySQL、Oracle)、SqlServer

SQL

结构化查询语言(Structure Query Language),专门用来与数据库通信的语言。

  • 优点:
    1. 几乎所有DBMS都支持SQL
    2. 简单易学
    3. 强有力语言,可以进行非常负责和高级的数据库操作

三、数据库存储数据特点

  1. 数据存放到表中,然后表再放到库中
  2. 一个库中可以有多张表,每张表具有唯一性的表名用来标识自己
  3. 表具有一些特性,这些特性定义了数据在表中如何存储,类似java中“类”的设计。
  4. 表中有一个或多个列,列又称为“字段”,每一字段类似于java中“属性”
  5. 表中的数据按行存储的,每一行类似于java中“对象”

四、MySQL介绍及安装使用

MySQL配置文件介绍

  • 安装路径中的my.ini配置文件,右键由写字板打开,将来有需要更改的配置大概在如下内容,根据需求更改即可:

    # SERVER SECTION
    # ----------------------------------------------------------------------
    #
    # The following options will be read by the MySQL Server. Make sure that
    # you have installed the server correctly (see above) so it reads this 
    # file.
    #
    [mysqld]
    
    # The TCP/IP Port the MySQL Server will listen on
    port="xxxxxxxxxxxxxxxxx我肯定不能展示出来呀!xxxxxxxxxxxxxxxxxxxxxxxxxx"
    
    
    #Path to installation directory. All paths are usually resolved relative to this.
    basedir="xxxxxxxxxxxxxxxxx我肯定不能展示出来呀!xxxxxxxxxxxxxxxxxxxxxxxxxx"
    
    #Path to the database root
    datadir="xxxxxxxxxxxxxxxxx我肯定不能展示出来呀!xxxxxxxxxxxxxxxxxxxxxxxxxx"
    
    # The default character set that will be used when a new schema or table is
    # created and no character set is defined
    character-set-server=utf8
    
    # The default storage engine that will be used when create new tables when
    default-storage-engine=INNODB
    
    # Set the SQL mode to strict
    sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    
    # The maximum amount of concurrent sessions the MySQL server will
    # allow. One of these connections will be reserved for a user with
    # SUPER privileges to allow the administrator to login even if the
    # connection limit has been reached.
    max_connections=100
    
    
    

MySQL服务启动和停止

  1. 方式一:手动操作

    • 计算机 > 右键管理 > 服务和应用程序 > 服务 > 找MySQL > 选中右键点属性更改启动类型 / 选中右键点击启动或停止
  2. 方式二:命令行操作

    • 以管理员身份打开cmd :

      C:\WINDOWS\system32>net start 服务名
      C:\WINDOWS\system32>net stop 服务名
      

MySQL服务端的登录和退出

在MySQL启动的基础上,才可以进行登录和退出操作

  • 方式一:打开MySQL 5.5 Command Line Client,适用于root用户

    • 登录:直接输入root的登录密码
    • 退出:exit / ctrl + c
  • 方式二:用命令行操作,适用于所有用户

    • 登录:以管理员身份打开cmd :

      # -h , 即host主机
      # -P , 即Port端口号
      # -u , 即root用户名
      # -p , 即password
      
      C:\WINDOWS\system32>mysql -h localhost -P 3306 -u root -p
      Enter password: ****
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 1
      Server version: 5.5.15 MySQL Community Server (GPL)
      
      Copyright (c) 2000, 2010, 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.
      
      mysql>
      
    • 退出:exit / ctrl + c


五、MySQL命令

MySQL版本查看

  • 方式一:通过cmd管理员运行

    # mysql -V
    C:\WINDOWS\system32>mysql -V
    mysql  Ver 14.14 Distrib 5.5.15, for Win32 (x86)
    
  • 方式二:登录进MySQL服务端后用命令行

    # select version();
    mysql> select version();
    +-----------+
    | version() |
    +-----------+
    | 5.5.15    |
    +-----------+
    1 row in set (0.10 sec)
    

MySQL常见命令

1.查看当前所有的数据库
show databases;

2.打开指定的库
use 库名;

3.查看当前库的所有表
show tables;

4.查看其他库的所有表
show tables from 库名;

5.创建一个表
create table 表名(
   列名 列类型,
   列名 列类型,
   ...
);

6.查看表结构
desc 表名;


六、MySQL语法规范

  1. MySQL不区分大小写,但建议关键字大写,表名,列名小写
  2. 每条命令最好用分号结尾
  3. 每条命令根据需要,可以进行缩进或换行,建议关键字单独一行
  4. 注释:
    • 单行注释:#注释文字
    • 单行注释:-- 注释文字
    • 多行注释:/* 注释文字 */

七、数据库图像化管理工具客户端安装

两者使用教程:http://xpbag.com/366.html

SQLyog

posted @ 2023-04-04 21:32  陈景中  阅读(15)  评论(0编辑  收藏  举报