安装指南:

https://www.cnblogs.com/majj/p/9160383.html  小马哥

下载完后初始化操作数据库:

1. 将文件放在 :

G:\软件\mysql-8.0.15-winx64\bin

2. 执行初始化命令

进入 bin目录下 进行初始化

mysqld --initialize-insecure --user=mysql 

3.启动mysql

net start mysql

4. 如果step3 失败的话,执行mysqld -install 命令 ,这个命令需要在admin管理

mysqld -install

5. mysql 8版本可能需要root密码,我们重置一下密码:

1、先关掉系统服务

net stop mysql

2、进入mysql安装目录的bin文件中,以管理员的方式运行cmd,然后输入如下命令,实现无密码登陆

mysqld --console --skip-grant-tables --shared-memory

3、以空密码登入系统

mysql.exe -u root

4、重置密码

UPDATE mysql.user SET authentication_string='root' WHERE user='root' and host='localhost';

1. 新建数据库,表

1. 创建数据库
mysql> create database maizi1;
Query OK, 1 row affected (0.01 sec) mysql> create database if not exists maizi default character set "utf8";
Query OK, 1 row affected (0.00 sec) mysql> use maizi;
Database changed
mysql> 2. 创建数据库表 user
create table if not exists user(
id smallint,
username varchar(20),
age tinyint,
sex enum("男","女","保密"),
email varchar(50),
addr varchar(200),
birth YEAR,
salary float(8,2),
tel int,
married tinyint(1) comment "0,代表未婚.非零代表已经结婚."
)engine =innodb charset =utf8; 3. 创建 数据库表 course
create table if not exists course(
cid tinyint,
couseName varchar(50),
courseDesc varchar(200)
); 4. 创建表cms
create table if not exists cms_cate(
id tinyint,
cateName varchar(50),
cateDesc varchar(200)
)engine=myisam charset =utf8; 5. 创建表cms_news
create table if not exists cms_news(
id int,
title varchar(50),
content text,
pubTime int,
clickNum int,
isTop tinyint(1) comment "0代表不置顶,1代表置顶."
);

2.查看数据库表

6. 查看表结构

mysql> describe user;
+----------+------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------------+------+-----+---------+-------+
| id | smallint(6) | YES | | NULL | |
| username | varchar(20) | YES | | NULL | |
| age | tinyint(4) | YES | | NULL | |
| sex | enum('男','女','保密') | YES | | NULL | |
| email | varchar(50) | YES | | NULL | |
| addr | varchar(200) | YES | | NULL | |
| birth | year(4) | YES | | NULL | |
| salary | float(8,2) | YES | | NULL | |
| tel | int(11) | YES | | NULL | |
| married | tinyint(1) | YES | | NULL | |
+----------+------------------------+------+-----+---------+-------+ mysql> show columns from user;
+----------+------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------------+------+-----+---------+-------+
| id | smallint(6) | YES | | NULL | |
| username | varchar(20) | YES | | NULL | |
| age | tinyint(4) | YES | | NULL | |
| sex | enum('男','女','保密') | YES | | NULL | |
| email | varchar(50) | YES | | NULL | |
| addr | varchar(200) | YES | | NULL | |
| birth | year(4) | YES | | NULL | |
| salary | float(8,2) | YES | | NULL | |
| tel | int(11) | YES | | NULL | |
| married | tinyint(1) | YES | | NULL | |
+----------+------------------------+------+-----+---------+-------+
10 rows in set (0.00 sec)

3.创建主键与自增长

7. 创建主键.(可以省掉primary 关键字.)
mysql> create table if not exists user1(
-> id int primary key,
-> username varchar(20)
-> );
Query OK, 0 rows affected, 1 warning (0.00 sec) 查看表.
mysql> desc user1;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| username | varchar(20) | YES | | NULL | |
+----------+ -------------+------+-----+---------+-------+
2 rows in set (0.00 sec) mysql> 8.设置复合主键.
mysql> create table if not exists user2(
-> id int,
-> username varchar(20),
-> card char(18),
-> primary key(id,card)
-> );
Query OK, 0 rows affected (0.04 sec) 9. 自增长. auto_increment mysql> create table if not exists user10(
-> id smallint key auto_increment,
-> username varchar(20)
-> );
Query OK, 0 rows affected (0.04 sec) mysql> desc user10;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | smallint(6) | NO | PRI | NULL | auto_increment |
| username | varchar(20) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

4.非空、默认与唯一约束

10. 非空. NOT NULL.

mysql> create table if not exists user7(
-> id int unsigned key auto_increment,
-> username varchar(20) not null,
-> password char(32) not null,
-> age tinyint unsigned
-> );
Query OK, 0 rows affected (0.06 sec) mysql> desc user7;
+----------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(20) | NO | | NULL | |
| password | char(32) | NO | | NULL | |
| age | tinyint(3) unsigned | YES | | NULL | |
+----------+---------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec) mysql> insert user7(username,password) values("king","king")
-> ;
Query OK, 1 row affected (0.00 sec) 11. DEFAULT 默认值. mysql> create table if not exists user8(
-> id int unsigned key auto_increment,
-> username varchar(20) not null,
-> password char(32) not null,
-> age tinyint unsigned default 19,
-> addr varchar(50) not null default "北京"
-> );
Query OK, 0 rows affected (0.04 sec) mysql> desc user8
-> ;
+----------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(20) | NO | | NULL | |
| password | char(32) | NO | | NULL | |
| age | tinyint(3) unsigned | YES | | 19 | |
| addr | varchar(50) | NO | | 北京 | |
+----------+---------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec) 12. 唯一约束.unique mysql> create table if not exists user11(
-> id tinyint unsigned key auto_increment,
-> username varchar(20) not null unique ,
-> card char(18) unique
-> );
Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> desc user11;
+----------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+----------------+
| id | tinyint(3) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(20) | NO | UNI | NULL | |
| card | char(18) | YES | UNI | NULL | |
+----------+---------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec) mysql> insert user11(username) value("a");
Query OK, 1 row affected (0.01 sec) mysql> select * from user11;
+----+----------+------+
| id | username | card |
+----+----------+------+
| 1 | a | NULL |
+----+----------+------+
1 row in set (0.00 sec)

5.重命名、添加字段

13. 重命名表名.
mysql> create table user13(
-> id smallint unsigned key auto_increment,
-> username varchar(20)not null unique,
-> password char(32) not null,
-> email varchar(50) not null default "393376780@qq.com",
-> age tinyint unsigned default 18,
-> addr varchar(200) not null default " 北京",
-> salary float(6,2),
-> regTime int unsigned,
-> face char(100) not null default "default.jpg"
-> );
Query OK, 0 rows affected (0.03 sec) mysql> desc user13;
+----------+----------------------+------+-----+------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------------+------+-----+------------------+----------------+
| id | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(20) | NO | UNI | NULL | |
| password | char(32) | NO | | NULL | |
| email | varchar(50) | NO | | 393376780@qq.com | |
| age | tinyint(3) unsigned | YES | | 18 | |
| addr | varchar(200) | NO | | 北京 | |
| salary | float(6,2) | YES | | NULL | |
| regTime | int(10) unsigned | YES | | NULL | |
| face | char(100) | NO | | default.jpg | |
+----------+----------------------+------+-----+------------------+----------------+
9 rows in set (0.00 sec) mysql> alter table user13 rename to user31;
Query OK, 0 rows affected (0.01 sec) mysql> rename table user31 to user13;
Query OK, 0 rows affected (0.01 sec) 14. 添加字段. mysql> alter table user13 add card char(18);
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0 #在username字段后面添加字段.
mysql> alter table user13 add test10 int not null default 100 after username;
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0 #在第一个字段位置添加.
mysql> alter table user13 add test100 int not null default 100 first;
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0 15. 删除字段. mysql> alter table user13 drop test10;
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0 16. 修改字段属性 mysql> alter table user13 modify card varchar(200);
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table user13 change card cardchange char(44);
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> desc user13;
+------------+----------------------+------+-----+------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------------------+------+-----+------------------+----------------+
| test100 | int(11) | NO | | 100 | |
| id | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(20) | NO | UNI | NULL | |
| password | char(32) | NO | | NULL | |
| email | varchar(50) | NO | | 393376780@qq.com | |
| age | tinyint(3) unsigned | YES | | 18 | |
| addr | varchar(200) | NO | | 北京 | |
| salary | float(6,2) | YES | | NULL | |
| regTime | int(10) unsigned | YES | | NULL | |
| face | char(100) | NO | | default.jpg | |
| cardchange | char(44) | YES | | NULL | |
+------------+----------------------+------+-----+------------------+----------------+
11 rows in set (0.00 sec)

6. 主键与索引操作

1. 复合索引.
mysql> alter table user1 add primary key(id,username);
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> desc user1;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| username | varchar(20) | NO | PRI | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec) 2. 删除主键
mysql> alter table user1 drop primary key;
Query OK, 0 rows affected (0.52 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> desc user1;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(11) | NO | | NULL | |
| username | varchar(20) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec) 3. 唯一索引. mysql> alter table user1 add unique(username);
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> desc user1;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| username | varchar(20) | NO | PRI | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec) mysql> alter table user12 add constraint symbol unique key uni_card(face);
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> desc user12;
+----------+----------------------+------+-----+------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------------+------+-----+------------------+----------------+
| id | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(20) | NO | UNI | NULL | |
| password | char(32) | NO | | NULL | |
| email | varchar(50) | NO | | 393376780@qq.com | |
| age | tinyint(3) unsigned | YES | | 18 | |
| addr | varchar(200) | NO | | 北京 | |
| salary | float(6,2) | YES | | NULL | |
| regTime | int(10) unsigned | YES | | NULL | |
| face | char(100) | NO | UNI | default.jpg | |
+----------+----------------------+------+-----+------------------+----------------+
9 rows in set (0.00 sec) 修改默认引擎.
mysql> alter table user1 ENGINE=MyISAM;
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0

Mysql-基础+安装指南的更多相关文章

  1. Mysql基础代码(不断完善中)

    Mysql基础代码,不断完善中~ /* 启动MySQL */ net start mysql /* 连接与断开服务器 */ mysql -h 地址 -P 端口 -u 用户名 -p 密码 /* 跳过权限 ...

  2. MYSQL基础操作

    MYSQL基础操作 [TOC] 1.基本定义 1.1.关系型数据库系统 关系型数据库系统是建立在关系模型上的数据库系统 什么是关系模型呢? 1.数据结构可以规定,同类数据结构一致,就是一个二维的表格 ...

  3. 【夯实Mysql基础】记一次mysql语句的优化过程

    1. [事件起因] 今天在做项目的时候,发现提供给客户端的接口时间很慢,达到了2秒多,我第一时间,抓了接口,看了运行的sql,发现就是 2个sql慢,分别占了1秒多. 一个sql是 链接了5个表同时使 ...

  4. MySQL基础(非常全)

    MySQL基础 一.MySQL概述 1.什么是数据库 ? 答:数据的仓库,如:在ATM的示例中我们创建了一个 db 目录,称其为数据库 2.什么是 MySQL.Oracle.SQLite.Access ...

  5. mysql 基础篇5(mysql语法---数据)

    6 增删改数据 -- ********一.增删改数据********* --- -- 1.1 增加数据 -- 插入所有字段.一定依次按顺序插入 INSERT INTO student VALUES(1 ...

  6. MySQL 基础语句

    MySQL 基础语句 多个知识点 ----------------------------------------------------------------------------------- ...

  7. MySQL:基础—数据分组

    MySQL:基础-数据分组 1.为什么要分组: 比如一个表中有多条订单记录,如上图,每条记录对应着一个商品,现在我要查询 每个商品被订购的单数 准备出货?也就是找到每个商品被订购的数量. 如果只找一个 ...

  8. MySQL基础学习总结

    1.MySQL基础概念 mysql逻辑架构如下: 每个客户端连接都会在服务器中拥有一个线程,这个连接的查询只会在这个单独的线程中执行. MySQL是分层的架构.上层是服务器层的服务和查询执行引擎,下层 ...

  9. MySQL基础(五)——视图

    MySQL基础(五)--视图

  10. MySQL基础(四)——索引

    MySQL基础(四)--索引

随机推荐

  1. 【转】Https内部机制基础知识

    互联网权威机构 - CA 机构,又称为证书授权 (Certificate Authority) 机构,浏览器会内置这些"受信任的根证书颁发机构" (即 CA). 数字证书 提及 H ...

  2. Linux sar

    一.简介 sar(System Activity Reporter系统活动情况报告)是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告,包括:文件的读写情况.系统调 ...

  3. Byte字节与位

    位(bit)字节(byte)一字节是8位所以2Byte是16位二进制

  4. 五个步骤搞定敏捷UX设计

    互联网产品发展的速度越来越快,人们对于产品的要求也在不断的升级,这直接地导致了用户体验设计的重要性不断提升.与此同时,过去的流程冗长的设计开发模式已经不能够满足快速迭代的需要.<敏捷宣言> ...

  5. ejb 和pojo , jboss 和 tomcat

    EJB(企业JavaBeans)是普通JavaBeans的一种提升和规范,因为企业信息系统开发中需要一个可伸缩的性能和事务.安全机制,这样能保证企业系统平滑发展,而不是发展到一种规模重新更换一套软件系 ...

  6. pca总结,非常详细

    #coding=utf- from numpy import * '''通过方差的百分比来计算将数据降到多少维是比较合适的, 函数传入的参数是特征值和百分比percentage,返回需要降到的维度数n ...

  7. 共享内存system v(未编译)

    #include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> ...

  8. Jsp的语法和指令

    Jsp的三种注释 前端语言注释:<!-- --> 会被转译,也会被发送,但是不会被浏览器执行 java语言注释: 会被转译,但是不会被servlet执行 Jsp注释:<%--  -- ...

  9. 解决yum安装时 Cannot retrieve repository metadata (repomd.xml) for repository

    打开/etc/yum.repos.d/CentOS6-Base-163.repo 将下面的baseUrl的地址换成网上最新 # CentOS-Base.repo## The mirror system ...

  10. Hdu1978 How many ways 2017-01-18 14:32 40人阅读 评论(0) 收藏

    How many ways Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total ...