mysql 1 3306_MySQL【1】-3306默认端口

这篇博客介绍了如何在cmd中安装MySQL并进行基本操作,包括启动、连接和退出数据库。此外,还概述了数据库管理系统(DBMS)的分类,重点讲解了MySQL的默认端口3306。博客中详细解释了SQL语言,如查询、排序、过滤数据的基本语法,并通过实例进行了演示。
摘要由CSDN通过智能技术生成

MySQL【1】

cmd中进行:安装: mysqld -install

启动: net start mysql

链接:

mysql -uroot -proot (用户名:root, 密码:root)

mysql -hlocalhost -p3306 -uroot –proot (-h代表主机地址 -p3306—MySQL默认端口未被占用的前提下)

mysql -hlocalhost -p3306 -uroot -p "回车"

Enter password:

6c1834fcfb91

image.png

退出: exit或者quit;

6c1834fcfb91

image.png

数据库管理系统(DBMS)分类

1.基于共享文件系统的DBMS,如Microsoft Access和FileMaker。

2.基于客户机—服务器的DBMS,如MySQL(默认端口号:3306)、 Oracle(默认端口号:1521)以及Microsoft SQL Server(默认端口号:1433);

SQL(Structured Query Language)

SQL是一种专门用来与数据库通信的结构化查询语言。

数据库(database)保存有组织的数据的容器(通常是一个文件或一组文件)。

表(table) 某种特定类型数据的结构化清单。

列(column) 表中的一个字段。所有表都是由一个或多个列组成的。

数据类型(datatype) 所容许的数据的类型。每个表列都有相应的数据类型,它限制(或容许)该列中存储的数据。

行(row) 表中的一个记录。

主键(primary key)

1.一列(或一组列),其值能够唯一区分表中每个行。

2.表中的任何列都可以作为主键,只要它满足以下条件:

任意两行都不具有相同的主键值;

每个行都必须具有一个主键值(主键列不允许NULL值)。

MySQL常用语法

1.显示所有的数据库:show databases;

2.创建数据库:

create database databasename;

create database [if not exists] databasename;

例如:create database students;

create database if not exists students1;

3.删除数据库: drop database databasename;

例如:drop database students;

4.导入sql文件: source 被导文件所在的路径/被导文件名(若是错误则改成\)

source E:/MySQL/testdata/mysql_scripts/create.sql

source E:/MySQL/testdata/mysql_scripts/populate.sql

5.查询版本号:select version();

6.查看报错信息: show errors;

7.选中数据库:use databasename;(分号可省略)

例如:use students1

8.显示所有可能的表:show tables;

9.显示表结构:

desc tablename;

show columns from tablename;

show full columns from tablename; 相对于上2条更详细(备注等信息)

例如:desc students1;

show columns from students1;

show full columns from students1;

查询表内数据:

1.查询所有列: select * from tablename;

例如:select * from students1;

2.查询多列: select columnname1,columnname2,…,columnnameN from tablename;

例如:select id,name,age from students1;

3.查询单列: select columnname from tablename;

例如:select id from students1;

4.去重复,查询不同的数据:distinct

例如:

select distinct prod_price from products;

select distinct prod_price,prod_desc from products;

5.排序:order by 默认升序(asc),降序(desc)

例如:

select prod_price from products order by prod_price;

select prod_price from products order by prod_price asc;

select prod_price from products order by prod_price desc;

select prod_price,prod_id from products order by prod_price desc ,prod_id; 表示先进行价格降序排列,再进行编号升序排序

6.限制查询:limit

limit n:显示前n条记录

limit m,n:显示从行m(第m+1行)开始的n行;

例如:

select prod_price from products limit 5;

select prod_price from products limit 5,3;

limit 和order by联用可以显示最高或者最低的几个;

例如:

select prod_price from products order by prod_price desc limit 3;

select prod_price from products order by prod_price desc limit 1;

select ceshi81.products.prod_price from ceshi81.products order by prod_price desc limit 1;

过滤数据:where

= , > , < ,>= , <=, != or <> 不等于

例如:

select prod_id from products where vend_id=1001;

select * from products where prod_price>10;

select * from products where prod_name='apple';

select * from products where prod_name>'Fuses'; 字符从第一个字符开始比较,比F大;若相同则进行第二个字符比较比u大

select distinct prod_name from products where vend_id=1003 limit 3;

2.区间: between and 含边界

Not between and

例如:select prod_price from products where prod_price between 10 and 35; 10<=prod_price<=35

select prod_price from products where prod_price not between 10 and 35;

3.空值查询: is null

is not null

例如: select * from vendors where vend_state is NULL;

select * from vendors where vend_state is not NULL;

组合where子句:

1.and 同时满足

select * from products where vend_id=1003 and prod_price <=10;

2.or 满足其中一个条件

select * from products where vend_id=1003 or vend_id=1005;

select * from products where vend_id=1003 or prod_price <=10 ;

select * from products where vend_id=1003 or vend_id=1005 and prod_price<=10.0; and优先级比or高

select * from products where vend_id=1003 or (vend_id=1005 and prod_price<=10.0); 先进行括号里面的筛选

3.in 操作符(等同于or) [not in]

select * from products where vend_id=1003 or vend_id=1005 or vend_id=1001;

select * from products where vend_id in(1001,1003,1005);

综合案例:

select distinct prod_price

from products

where vend_id in (1001,1003,1005)

order by prod_price desc

limit 3;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值