On the 30th day, related concepts of database management software, installation and configuration of mysql basic sql statements (database, table, data addition, query, modification, and deletion)

Concepts related to database management software

Database management software: the essence is a socket program with cs architecture (a program developed to solve the problem of storing data in local files)
server socket client socket
operating system operating system
computer (local file) computer hardware

1. It is impossible for all the components of the program to run on one computer.
A computer has limited performance. We need to distribute the components of the program on multiple machines to execute

2. Data security issues
Each computer can only operate on local files, which leads to inconsistencies in
data. Separate data from applications, store files on one machine, and then multiple machines to access this machine through the network Files to realize data sharing (data security issues need to be locked to deal with issues...)

3. Concurrency
Remote connection (support concurrent) to
open the file,
read and write (lock) to
close the file

Common database management software

Relational database management software (there is a relationship between the table and the table)
mysql, oracle
to IOE movement

Non-relational database management software (key:value database)
redis, memcache, mongodb (back-end data to use)
redis, memcache is usually used as a cache, put the data in the memory and use
mongodb (as the back-end Data to use)

Non-relational database: fast query
Relational database: convenient management

sql statement: the command specification specified by the author of the socket management software for the user

Summary of important concepts of the database
Data-------------------"State
record of things -------------------"File A piece of information in
Table --------------------- "A file
library -------------------- -"Folder
Header-------------------" Fields in the first row of the form
------------------ -"Field name + field type
Database management software-----------"Socket program: mysqld (server), mysql (client)
database server------------ -"The computer running mysqld

database? ? ?
It may refer to the library, it may also refer to the database management software, or the database server

Download and install the mysql software on the windows system. After downloading and installing
, you need to open two ports when you use it, one is the server (mysqld) and the other is the client (mysql)
. Enter the command "mysqld" in cmd to open the server, and then open A cmd port input command "mysql -u (user name) root -p (password) -h (ip) -P (port number, default port number 3306)"

When mysql was configured in the early stage, the cmd terminal came in to run
windows+r as an administrator. Enter cmd and enter the ordinary user terminal. There are some commands that cannot be executed.
Search cmd right click to run as an administrator

Start mysql and
switch to the directory where mysql is located, and then enter mysql to
keep the original cmd window and reopen one

Common software default port numbers

mysql 3306
redis 6379
mongpdb 27017
django 8000
flask 5000

There is no password when mysql enters as an administrator for the first time

The complete command for the client to connect to the server: mysql -h 127.0.0.1 -P 3306 -uroot -p

First acquaintance of sql statement

1.mysql中的sql语句是以分号作为结束的标志

2.基本命令
    show databases;(查看所有的数据库名)
    
3.连接服务端的命令可以简写
    mysql -uroot -p
    
4.当你输入的命令不对,又不想让服务端执行返回报错信息可以用\c取消
    错误命令 \c取消
    
5.客户端退出 退出命令加不加分号都可以
    quit
    exit

6.当你在连接服务端的时候发现输入mysql也能连接
    但是你不是管理员身份 而只是一个游客模式

Environment variable configuration and system service production

小知识点补充
1.如何查看当前具体进程2
    tasklist
    tasklist |findstr mysqld

2.如何杀死具体进程(只有在管理员cmd窗口下才能成功)
    taskkill /F /PID PID号

Environment variable configuration

每次启动mysql需要先切到对应的文件路径下才能操作太过繁琐
将mysqld所在的文件路径添加到系统环境变量中

将mysql服务端制作成系统服务(开机自启动),这样就不需要两个cmd窗口了
查看当前计算机运行的进程数
    service.msc
将mysql制作成系统服务
    mysqld --install
移除mysql系统服务
    mysqld --remove


设置密码
mysqladmin -uroot -p原密码 password 新密码
该命令直接在终端输入即可,无需进入客户端

Skip the authorization and reset the password (password cracking ). The
function of myql to obtain the user name and password verification can be regarded as a decorator. If we remove the
decorator from the client request access function
, then the mysql service The end will not verify the user name and password

1.先关闭当前mysql服务端
命令行的方式启动(让mysql跳过用户名密码验证功能)
mysqld --skip-grant-tables跳过授权表启动
2.直接以无密码的方式连接
mysql -uroot -p 直接回车
3.修改当前用户的密码
update mysql.user set password=password(123) where(注意,一定要使用where指定修改的密码,不然会把数据库所有的密码都改成123)
user="root" and host="localhost"

真正存储用户表的密码字段,存储的肯定是密文
只有用户自己知道明文是什么,其他人都不知道,这样更加的安全
密码比对也只能比对密文

4.立刻将修改的数据刷到硬盘
flush privileges
5.关闭当前服务端,然后以正常校验授权的形式启动

Uniform coding, configuration does not require a password to log in as an administrator directly

After modifying the configuration file, the mysql service must be restarted to take effect (note that)

mysql默认的配置文件
my-default.ini
ini结尾的一般都是配置文件
程序启动会先加载配置文件中的配置之后才真正启动
[mysqld] # 一旦服务端启动立刻加载下面的配置
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql] # 一旦客户端启动立刻加载下面的配置
。。。
[client] # 其他客户端
。。。

需要你自己新建一个my.ini的配置文件
验证配置是否真的会自动加载
[mysql]
print("hello world")

修改配置文件后一定要重启mysql服务才能生效(重点注意)

统一编码的配置 无需掌握 直接拷贝即可
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

将管理员的用户名和密码也添加到配置文件中后,
之后启动mysql数据库就不需要输入用户名和密码了 直接输入mysql会直接以管理员身份启动
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
[mysql]
user="root"
password=123
default-character-set=utf8

Basic SQL statement
ps: The business logic of most programs is actually adding, deleting, modifying and checking

Add, delete, modify and check the library (folder)

增:create database db1;(指定编码格式的完整命令为:create database db1 charset="gbk";)
查:show databases; (查所有)
    show create database db1; (查单个)
改:alter database db2 charset="utf8"
删:drop database db2;

Additions, deletions, and modifications to tables (files)

在操作表(文件)的时候 需要指定所在的库
查看当前所在的库的名字:select database();
切换库:use db1;
增:create table t1(id int,name char(4));
查:show tables; (查看当前库下的所有表名)
    show create table t1;(查当前库下的指定表信息)
    describe t1;(将当前表的信息以表格的形式展示,支持简写 desc t1;)
改:alter table t1 modify name char(16);
删:drop table t1;

表的增查改删也可以以绝对路径的形式进行操作,无需切换文件路径
create table db2.t1(id int);(例如在文件db1路径下,新增加一个db2库中的t1的表格)

Add, delete, modify and check data (row by row of data)

一定要现有库 有表 最后才能操作记录
增:insert into t1 values(1,"nana");
    insert into t1 values(1,"nana"),(2,"dada"),(3,"tank")
查:select * from t1; (该命令当数据量特别大的时候不建议使用,*号代表所有的意思)
#    select id,name from t1; (将t1中所有用户的id,名字显示出来)   
简写  select name from t1; (将t1中所有用户的名字显示出来)
改:update t1 set name="lala" where id = 1;(将id等于1的名字改成lala)
删:delete from t1 where id > 1; (将id大于1的数据全部删除)
    delete from t1 where name ="tank"; (将名字为tank的数据删除)
将表所有的数据清空:delete from t1;

Guess you like

Origin blog.csdn.net/Yosigo_/article/details/113519255