MySQL学习笔记(一)
by 呆萌同学
一、数据库的相关概念
1. DB
数据库(Database):存储数据的“仓库”。它保存了一系列有组织的数据。
2. DBMS
数据库管理系统(Database Management System)。数据库是通过DBMS创建和操作的。
常见的DBMS:MySQL、Oracle(甲骨文)、DB2(IBM)、SqlServer(微软)等。
3. SQL
结构化查询语言(Structure Query Language):专门用来与数据库通信的语言。
几乎所有DBMS都支持SQL。
二、数据库存储特点
- 数据放入表中,表再放入库中。
- 一个数据库中可以有多个表,每个表都有一个名字用于标识自己,表名具有唯一性。
- 表具有一些特性,这些特性定义了数据在表中如何存储。
- 表由列组成,也称为字段。
三、MySQL数据库特点
- 隶属于MySQLAB公司,后被oracle收购。
- 成本低,性能高,安装和使用简单。
- 分社区版和企业版。
四、两类DBMS
- 基于共享文件系统的DBMS
例如:Access - 基于客户机——服务器的DBMS
例如:MySQL、Oracle、SqlServer
使用时既要安装客户端又要安装服务端。一般来说“安装”指安装服务端。
五、MySQL的安装
前往官网下载MySQL Community Server并安装:
https://dev.mysql.com/downloads/mysql
六、MySQL的启动与停止
windows:
方法一:计算机-右击管理-服务
方法二:命令行(以管理员身份方式运行):
启动:net start 服务名
停止:net stop 服务名
mac:
进入系统偏好设置,找到MySQL打开,点击"Start MySQL Server",启动mysql;或点击"Stop MySQL Server",停止mysql
七、my.ini配置文件
- 服务端端口号 port=3306
- 安装目录 basedir
- 文件存储目录 datadir
- 字符集 character-set-server=utf8
- 存储引擎(用来执行SQL语句) default-storage-engine=INNODB
- 语法模式 sql-mode=“STRICT_TRANS_TABLES, NO_AUTO_CREATE)USER, NO_ENGINE_SUBSTITUTION”
- 最大连接数 max_connections=100
八、MySQL服务端的登陆和退出
首先保证MySQL为启动状态。
windows:
在命令行输入
mysql [-h localhost -P 3306] -u root -p //[ ]内的内容可以省略
回车后输入密码进入,输入exit退出
mac:
在终端输入
mysql [-h localhost -P 3306] -u root -p //[ ]内的内容可以省略
回车后输入密码进入,输入exit退出
九、查看MySQL版本
方法一:终端或命令行登陆MySQL,然后输入
select version();