10.28MySQL introduction and installation

What is the database

The existence of a data warehouse

Why use a database (*********)

Before you can use Excel to manage data
Excel Cons:
can not manage large amounts of data
can not operate at the same time people
do not support the Advanced Operations
database:
support advanced operations (grouping, even tables, etc.)

Database classification (*********)

Relational Database

Data type of each column will be constrained (ID: Integer; name: String)
MySQL, maridb → use more free, two is the same author
SqlServer → Microsoft, universities, government departments, the car home
Oracle → Oracle, fees, finance companies, Ali
sqlite → small file database, their play, with no one

Non-relational databases

No constraints (the dictionary access) to the data type of each column
memcache → save memory, ten years before the product (Sina blog)
MongoDB → save memory, document database
redis → save memory, microblogging, to solve the problem disappear off memory

The biggest difference

Relational databases: the presence of the hard disk data (files)
non-relational databases: the data stored in memory

MySQL architecture

Similar to the Socket client and server
processes:
MySQL server to start listening in a particular port (3306)
MySQL client connection server
MySQL client can send the relevant operation command to operate the server storage data

MySQL installation (windows)

Go to the official website View

installation

'''
#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
#5、启动MySQL服务
mysqld # 启动MySQL服务
#6、启动MySQL客户端并连接MySQL服务
mysql -u root -p # 连接MySQL服务器
安装
'''

Set the system's service

'''
上一步解决了一些问题,但不够彻底,因为在执行【mysqd】启动MySQL服务器时,当前终端会被hang住,那么做一下设置即可解决此问题:
注意:--install前,必须用mysql启动命令的绝对路径
# 制作MySQL的Windows服务,在终端执行此命令:
"c:\mysql-5.7.16-winx64\bin\mysqld" --install
"D:\python培训\mysql-5.7.28\bin\mysqld" --install
# 移除MySQL的Windows服务,在终端执行此命令:
"c:\mysql-5.7.16-winx64\bin\mysqld" --remove
注册成服务之后,以后再启动和关闭MySQL服务时,仅需执行如下命令:
# 启动MySQL服务
net start mysql
# 关闭MySQL服务
net stop mysql
将MySQL服务制作成windows服务
'''

change Password

'''
初始状态下,管理员root,密码为空,默认只允许从本机登录localhost
设置密码
[root@egon ~]# mysqladmin -uroot password "123"
设置初始密码 由于原密码为空,因此-p可以不用
[root@egon ~]# mysqladmin -uroot -p"123" password "456"
修改mysql密码,因为已经有密码了,所以必须输入原密码才能设置新密码
命令格式:
[root@egon ~]# mysql -h172.31.0.2 -uroot -p456
[root@egon ~]# mysql -uroot -p
[root@egon ~]# mysql
以root用户登录本机,密码为空
'''

Common parameters

-u: user username
-p (lowercase): password password
-h: host host name or MySQL-uroot--p -h 192.168.1.10 IP
-P (uppercase): port default is 3306 mysql -uroot -p -h 192.168 .1.10 -P 3306

forget password

'''
方式一:
###  服务端  :服务端:  服务端
#1 关闭mysql的系统服务
#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
'''

Initial MySQL

SQL command

Database operations

Database naming convention

May consist of letters, numbers, underscore, @, #, $
case sensitive
uniqueness
can not create and select keywords
can not be used alone digital
longest 128

increase

create database database name;

delete

drop database database name; (if there is data folder will delete all) with caution

change

(Before the alter database database name database charset name) deleted add with caution

check

show databases;

Use Database

use database name;

Operation data table

Switching to the first folder: use db1

increase

create table t1(id int,name char);

delete

drop table t1;

change

alter table t1 modify name char(3)

check

show tables;

Operation table records (*********)

increase

insert into t1 values(1,'egon1'),(2,'egon2'),(3,'egon3');

delete

delete from t1 where id=1;

change

update t1 set name='sb' where id=2;

check

select * from t1;

Empty Table

delete from t1; (if there is data increment id, new, still is the same as the last start before they were removed.)
TRUNCATE the Table T1; (the amount of data, delete a speed faster than the previous, and direct from scratch .)

Find and accelerated increment

AUTO_INCREMENT (represented by: the self-energizing)
Primary Key (represented by: constraint (repeats not and can not be empty); accelerated lookup)

Guess you like

Origin www.cnblogs.com/793564949liu/p/11755958.html