database
First, what is the database
- Database: data management system - install a system for managing data - management is the essence of the object file
- Location to store the data: memory, hard disk
- What is the system: running on a hardware basis, other management software
Second, the composition of the database
- Library: store multiple tables - Folder
- Table: contains a plurality of records of the same structure - File
- Record: a data comprising a plurality of key-value pairs key - binary data
- Field: description information - information itself == key-value - binary data
stu
id name age gender
1 Bob 18 男
2 Tom 17 女
Third, the classification database
Relations with non-relational
Relations: a link between database tables and table - mysql
Non Relationship: No Table Concept - redis, mongodb (relationship between the non-relational)
Memory and hard drive
Hard disk: data can be stored permanently - mysql, mongodb
Memory: the high efficiency of data access - redis, memcache
sql and nosql
sql: database operated by sql statement
nosql: database operation is key-value form (value is one record)
STU - { 'name': 'Bob', 'Age': 18 is}
stus - [{ 'name': 'Bob' , 'Age': 18 is}, { 'name': 'Tom', 'Age': 18 is}]
name - 'Jerry'
Fourth, uninstall
Note: premise, start a terminal, enter mysql, if not prompt is not an internal or external command, on behalf of the database has been installed
Directly connected
Search: service, retrieve mysql service, if the service is turned on, stop the service and remove the service - Start administrator terminal: mysqld --remove
search for
Service, retrieve mysql service, no (use the mysql command to start)
Stop service, start the administrator terminal
tasklist | findstr mysql
taskkill /pid 进程pid /f
Connection timed out
Search: service, service to retrieve mysql, you can remove the service
- Remove environment variables
- If you can not even enter, to stop the service
- If you add a service, remove the service
- Cancellation environment variable configuration
V. Installation
- Download free installation unpack MySql version (5.6 - no initial password)
- Configuration environment variable
- Install server mysqld - install
- Start mysql
Sixth, the database connection
- Visitors landing
>>: mysql # may not be able to sign in, sign-up and consequently also can not do
- Account password
>>: mysql -u user name (root) -p password
eg: mysql -u root -p ‘123’
- Connected to the specified server MySql
>>: mysql -h ip address -P port number -u user name -p password
eg: mysql -h 127.0.0.1 -P 3306 -u root -p ‘123’
- Exit Database
>>: quit
>>: exit
Seven users View
- View the current logged-on user
>>: select user();
All users can see the information produced by the root authority
>>: select * from mysql.user; # display in the form of two-dimensional table
>>: select * from mysql.user \ G; # display as columns
>>: select user, password, host from mysql.user # view the user name, password, ip
The root login, delete tourists (after the operation to restart the mysql service)
>>: delete from mysql.user where user=“”;
The root login, change password (after the operation to restart mysql)
>>:update mysql.user set password = password(“密码”) where host=‘localhost’;
没有登录修改密码
>>:mysqladmin -u 用户名 -p 旧密码 -h 域名 password ‘新密码’
mysqladmin -u root -p ‘123’ -h locahlost password ‘123456789’
root登录下,创建用户
>>: grant 权限们 on 数据库名.表名 to 用户名@主机名 identified by '密码';
八、数据库的基本操作
查看已有的数据库
>>: show databases;
选择某个数据库
>>:use 数据库名
eg: use db1;
查看当前所有的数据库
>>: select database();
创建数据库
>>: create database 数据库名称 [charset=‘字符编码’];
eg: create database db1 # 编码格式默认
eg create dataase db2 charset = ‘utf8’
查看创建数据库的详细内容
>>: show create database 数据库名称
eg: show create database db1
删除数据库
>>:drop database 数据库
eg: drop database db1
九、表的基本操作
- 选择某个数据库
>>: user 数据库名;
eg user db;
- 查看已有的表
前提:先选取要操作的数据库
>>:show tables;
- 创建表(简易版)
>>: create table 表明(字段1 类型,….. 字段n 类型 );
eg: create table student(name);
- 查看创建表sql
>>: show create table 表名;
eg: show create table student;
- View table structure to create a sql statement
>>: desc table name;
eg: desc student;
- Delete table
>>:drop table 表名;
eg: drop table student;
Ten, the basic operation for recording
View a list of all records in a data (if in the corresponding database, you can direct look-up table, simple version)
>>: select * from table name; # Lite
eg: select name, id from student; # simple query
Inserting a plurality of fields to the table
>>: insert into table (field) values (= 1 field name field value, n = ... .. field name value, ... .;
eg: insert into student values (name = 'zhangsan', age = 29); # insert a data
eg: insert into student values (name = 'tom', age = 18), ( 'bob', 34); # inserting a plurality of values
eg: insert into db.student values (name = 'lisi', age = 10) # table inserted below the value specified library
Modify the contents specified by the condition
>>: update table set field name value = 1, 2 ... field name = value = value where field
eg: update student set name = ‘bob2’ , age=18 where name = ‘lisi’;
- Delete records according to the conditions
>>: delete from table where field name = value;
eg: delete from student where name=‘bob2’;