table of Contents
python day33
A database Overview
What is Data
Symbol data recording is referred to describe things
What is the database (DataBase, referred to as DB)
I.e. storage warehouse database data, which is a data warehouse on a computer storage device, and the data is located according to a certain format
Data in the database according to certain organizational data model, described and storage, has a smaller redundancy, higher data independence and easy scalability, and may be shared by other users
Database management system (DataBase Management System referred to as DBMS)
Database management system to better organize and store the data, and can efficiently obtain and maintain data
Commonly used: MySQL, Oracle, SQLite, SQLServer, etc.
Two internal membership database
Record : 1 Simple 88888 (composed of a plurality of fields of information recording, i.e., a line content file)
Table : student, school, class (that is, files)
Database : oldboy_stu (ie folder)
Database management systems : as mysql (a software)
Database server : A computer (higher memory requirements)
Summary :
Database server: database management software running
Database Management Software: Database Management
Database: the folder to organize your files / tables
Table: the file used to store a multi-line / multiple records
Three MySql Introduction
What is mysql
MySQL is a relational database management system
It is based on a written socket C / S software architecture
Database Software Category
Relational database (requires table structure)
MySql
Oracle
SQLite
SQLServer
Non-relational databases (a key: value stored, no structure table)
Mongodb
Redis
Download and install four
From the official website to download MySQl Community Server
https://www.mysql.com/downloads/mysql
Adding Environment Variables
In the cmd window initialization
mysql --initialize-insecure
Start the MySQL server
mysqld
Start the MySQL client and connect to the MySQL server
mysql -uroot -p
MySQL production of windows service, execute the command in a terminal
'Absolute path' --install
Start MySQL service
net start mysql
Shut down MySQL service
net stop mysql
Five basic MySQL management software
Login 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用户登录本机,密码为空
forget password
[root@egon ~]# vim /etc/my.cnf #mysql主配置文件
[mysqld]
skip-grant-table
[root@egon ~]# systemctl restart mariadb
[root@egon ~]# mysql
MariaDB [(none)]> update mysql.user set password=password("123") where user="root" and host="localhost";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> \q
[root@egon ~]# #打开/etc/my.cnf去掉skip-grant-table,然后重启
[root@egon ~]# systemctl restart mariadb
[root@egon ~]# mysql -u root -p123 #以新密码登录
方法二:启动时,跳过授权库
SQl statement
#1. 操作文件夹
增:create database db1 charset utf8;
查:show databases;
改:alter database db1 charset latin1;
删除: drop database db1;
#2. 操作文件
先切换到文件夹下:use db1
增:create table t1(id int,name char);
查:show tables
改:alter table t1 modify name char(3);
alter table t1 change name name1 char(2);
删:drop table t1;
#3. 操作文件中的内容/记录
增:insert into t1 values(1,'egon1'),(2,'egon2'),(3,'egon3');
查:select * from t1;
改:update t1 set name='sb' where id=2;
删:delete from t1 where id=1;
清空表:
delete from t1; #如果有自增id,新增的数据,仍然是以删除前的最后一样作为起始。
truncate table t1;数据量大,删除速度比上一条快,且直接从零开始,
auto_increment 表示:自增
primary key 表示:约束(不能重复且不能为空);加速查找