【MySQL】MySQL基础01 — 初识MySQL(转载请注明出处)
MySQL基础 — 初识MySQL
一、为什么要学习数据库
- 能够实现数据持久化
- 使用完整的管理系统统一管理,易于查询
二、数据库相关概念
DB
数据库(database),存储数据的“仓库”,保存了一系列有组织的数据
DBMS
数据库管理系统(Database Management System),DB是通过DBMS创建和操作的容器。常见的DBMS有:MySQL \ Oracle \ DB2 \ SQL Server
- 分类:
- 基于共享文件系统的DBMS:微软(Access)
- 基于客户机——服务器(C/S)的DBMS:甲骨文(MySQL、Oracle)、SqlServer
SQL
结构化查询语言(Structure Query Language),专门用来与数据库通信的语言。
- 优点:
- 几乎所有DBMS都支持SQL
- 简单易学
- 强有力语言,可以进行非常负责和高级的数据库操作
三、数据库存储数据特点
- 数据存放到表中,然后表再放到库中
- 一个库中可以有多张表,每张表具有唯一性的表名用来标识自己
- 表具有一些特性,这些特性定义了数据在表中如何存储,类似java中“类”的设计。
- 表中有一个或多个列,列又称为“字段”,每一字段类似于java中“属性”
- 表中的数据按行存储的,每一行类似于java中“对象”
四、MySQL介绍及安装使用
-
优点:
- 成本低,开放源代码
- 性能高,执行快
- 容易安装和使用
-
分类:
- 社区类(免费): https://downloads.mysql.com/archives/installer/
- 企业版(收费)
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服务启动和停止
-
方式一:手动操作
- 计算机 > 右键管理 > 服务和应用程序 > 服务 > 找MySQL > 选中右键点属性更改启动类型 / 选中右键点击启动或停止
-
方式二:命令行操作
-
以管理员身份打开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语法规范
- MySQL不区分大小写,但建议关键字大写,表名,列名小写
- 每条命令最好用分号结尾
- 每条命令根据需要,可以进行缩进或换行,建议关键字单独一行
- 注释:
- 单行注释:
#
注释文字 - 单行注释:
--
注释文字 - 多行注释:
/* 注释文字 */
- 单行注释:
七、数据库图像化管理工具客户端安装
两者使用教程:http://xpbag.com/366.html
SQLyog
- 下载地址:https://sqlyog.en.softonic.com/
- 专用于连接MySQL
Navicat
- 下载地址:http://www.navicat.com.cn/products
- 可以连接多种DBMS
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?