table of Contents
Installation of the database
One: What is the database
Literally: the data stored in the warehouse
Two: Why use a database? (***********)
Before using Excel to manage data,
The disadvantages of Excel:
1. manage large amounts of data can not (10W magnitude data)
2. concurrent operation with a data table
3. Data support advanced operations, such as: grouping, even tables, etc.
Three: classification database? (***********)
Relational database
to the data type of each column will be constrained, id (int), name (string type)
maridb, MySQL ----- "with more, free
SqlServer -----" Microsoft, university government (car home)
the Oracle ----- "Oracle, fees, finance companies, Ali
sqlite -----" small database files, their playmate
, etc.Non-relational database
memcache ---- "goods (Sina blog) ten years ago
mongodb ----" document database
redis ------ "microblogging{"name":'zekai'}
{"name":12}
{"name":[]}
{"name":{}}
The biggest difference:
relational database, the presence of hard disk data
non-relational database, the data stored in memory
Four: mysql architecture
Similar to the client and the server socket
流程:
1. mysql服务端先启动,监听在某一个特定的端口(3306)
2. mysql客户端连接服务端
3. mysql客户端就可以发送相关的操作命令,去操作服务端存储的数据
Five: mysql installation (windows)
windows安装:
先去官网(https://dev.mysql.com/downloads/mysql/)
#1、下载:MySQL Community Server 5.7.16
http://dev.mysql.com/downloads/mysql/
#2、解压
如果想要让MySQL安装在指定目录,那么就将解压后的文件夹移动到指定目录,如:C:\mysql-5.7.16-winx64
#3、添加环境变量
【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【将MySQL的bin目录路径追加到变值值中,用 ; 分割】
#4、初始化
mysqld --initialize-insecure ### 创建data目录, 初始化的数据
#5、启动MySQL服务
mysqld # 启动MySQL服务
#6、启动MySQL客户端并连接MySQL服务
mysql -u root -p # 连接MySQL服务器
mysql服务端不会阻塞住
制作windows的服务:
"D:\mysql-5.7.28\bin\mysqld" --install
修改mysql的密码:
C:\Windows\system32>mysqladmin -uroot -p "原密码" password "新密码"
出现的错误
C:\Windows\system32>mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
如果出现上述错误,代表密码输入错误
常用参数:(********************************)
-u : user 用户名
-p :password 密码
-h :host 主机名或ip mysql -uroot -p -h 192.168.1.10
-P : port 默认是3306 mysql -uroot -p -h 192.168.1.10 -P 3307
忘记密码,操作方式:
#1 关闭mysqld的服务
#2 在cmd中执行:mysqld --skip-grant-tables ===》 不用密码就可以登录,绕过密码验证的权限
#3 在cmd中执行:mysql ===》 mysql -uroot -p
#4 执行如下sql指令:
update mysql.user set authentication_string=password('') where user = 'root';
flush privileges; (一定要操作)
#5 tskill mysqld #或taskkill -f /PID 7832
#6 重新启动mysql服务
Six: mysql acquaintance
SQL 指令
- 操作数据库 (***************************************************************)
增
create database 数据库名称 charset utf8;
命名规范:
可以由字母、数字、下划线、@、#、$
区分大小写
唯一性
不能使用关键字如 create select
不能单独使用数字
最长128位
show create database 数据库名;
删
drop database 数据库名称;
改
删除再添加
如果数据库中有数据的话,直接drop会导致数据库中的数据丢失
在线上环境,不能够直接删除数据, 在删除之前,需要进行备份
查
show databases;
使用数据库:
use 数据库名;