Day01
First, build the database server
1. Install software that provides database services
What are the database service software?
Whether the software is cross-platform
Whether the software is open source (open source software is not equal to free, commercial software charges)
The source of the software
Package type of software (rpm, source code)
2. Installing the MySQL Software
See if you have this software
#rpm-Q mariadb
2.1 Uninstalling the MARIADB database, if any
#systemctl Status mariadb
#systemctl Stop MARIADB
#rpm-e--nodeps mariadb-server mariadb
#rm-rf/etc/my.cnf #mariadb配置文件
#rm-rf/etc/lib/mysql/* #数据库存储路径
Build the Environment
1. Install MySQL Database
Prepare the Mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar software package,
If it is not the same as the package operation, it is the package name modified below
[Email protected] ~]# TAR-XF Mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
[[email protected] ~]# ls
[Email protected] ~]# yum-y install Perl-data-dumper Perl-json
#安装依赖包, resolving dependencies
[Email protected] ~]# RM-RF mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm
[Email protected] ~]# RPM-UVH mysql-community-*.rpm
[Email protected] ~]# Rpm-qa | grep MySQL
2. Start the service:
Service name Process name Port number (3306) transport protocol
The process owner process belongs to the Group database directory
[Email protected] ~]# ps-c mysqld #查看进程是否启用
[Email protected] ~]# systemctl restart mysqld
[Email protected] ~]# Systemctl enable mysqld
[Email protected] ~]# Ls/var/lib/mysql #初始化文件
[Email protected] ~]# ps-c mysqld #查看进程是否启用
[Email protected] ~]# NETSTAT-NATUPL | grep 3306 #查看端口
[[Email protected] ~]# PS aux | Grep-i mysqld
[Email protected] ~]# grep mysql/etc/passwd #查看所有者和所属组
[Email protected] ~]# grep mysql/etc/group #查看组下面是否有没有mysql用户
3, those companies in the use of database services
Financial Institutions shopping Website Games website Forum website
4. Use of Web services and database services
LAMP LNMP
5. The process of storing data on a database server
A. Connecting to a database server
Log on to the database server with the initial password
Modify password Authentication policy and password length, change password
Modify the service's master profile to be permanent with a password validation policy
B. Building a library
C. Building a table
D. Inserting records
E. Disconnecting
A. Connect to the database server
[[email protected] ~]# which MySQL
/usr/bin/mysql
[[email protected] ~]# RPM-QF/ Usr/bin/mysql
mysql-community-client-5.7.17-1.el7.x86_64
[[email protected] ~]# grep password/var/log/ Mysqld.log #查看mysql日志和初始密码
Localhost:n6w/phw>dv+y #冒号后为系统分配的初始密码
[[email protected] ~]# mysql-uroot- P ' n6w/phw>dv+y ' #使用初始密码进入, Uroot for database management users and system root is not the same user
Mysql> set global validate_password_policy=0; Set Global password Authentication policy, 0 is not considered
Mysql> set global validate_password_length=6; #设置全局验证密码位数为6位
mysql> alter user [email protected] "localhost" identified by "123456"; #修改登录密码
Mysql> quit
[[email protected] ~]# vim/etc/my.cnf
[mysqld] #在最后添加
Validate_password_ policy=0
Validate_password_length=6
[[email protected] ~]# systemctl restart mysqld #重启服务
[[Email protected] ~]# mysql-uroot-p ' 123456 '
mysql> show databases; #显示数据库
Libraries and tables are stored as files in the database library directory.
B. Building a library (folder) view Create delete toggle
SQL syntax rules?
Mysql> show Tabels; #显示库里的
mysql> show databases; #显示数据库
mysql> CREATE Database Popo; #创建数据库
mysql> drop Database Popo; #删除数据库
Mysql> Select Database (); #查看当前所在的库
mysql> use Popo; #切换库
SQL command type: DDL DML DCL DTL
Command rules for a database
You can use numbers/letters/underscores, but not pure numbers
Case-sensitive, unique
Cannot use directive keywords, special characters
mysql> system Ls/var/lib/mysql #system可以在数据库中使用系统命令
C. Build the table (the table must be in the library)
Create Database studb; #创建表
CREATE table library name. Table Name (
Field Name Type (width) constraints,
Field Name Type (width) constraints,
......
);
Create Database studb; #创建表
CREATE TABLE Studb.dtuinfo (
Name Char (15),
Sex char (4),
Class char (7)
);
Rows are recorded in the table,
Columns are in the table for the field.
D. Inserting records: viewing, inserting, deleting, modifying records
INSERT into studb.stuinfo values ("Lucy", "Girl", "NSD1710"); #添加表里的内容
# ("Tom", "Girl", "nsd1709"), ("Herry", "Gril", "nsd1708"); #多个表同时添加
Delete from library name. Table name; #删除当前表里的记录
SELECT * from library name. Table name; #查看表里的内容
DESC Library name. Table name; #查看表结构
drop table Stuinfo; #删除表
Drop database studb; #删除库
Update library name. Table Name Set class= "nsd1709" where name= "Tom"; #修改表的信息
MySQL service build and basic understanding