Basic operations of the database
1. Create a database: Crete database database name;
Before creating the database table, use use database name m; and then create the database.
2. Create a database table: create table table name (field name data type constraints);
3. View the data table structure: desc table name; and show create table table name\g
4 .Constraints; primary key constraints primary key
Non-null constraints not null
Unique constraints unique
Default constraints default
Set the auto-increment of attribute values auto_increment
5. Modify the data table; modify the table name Alter table table name Rename new table name
Modify field name Alter table table name Modify field data type data type
Modify data type Alter Table Table name, old field, new field name data type data type
Add field alter table table Name ADD field name Data Type FIRST/AFTER field Name
Delete Field Alter Table Table Drop field Name
Storage engine Alter Table Table Name Engine = Storage Engine Summary: Modify: alter table table name modify etc;
Data type and operator
Data type: string type, numeric type, date and time type
1. Integer type; tinyint smallint mediumint int bigint.
2. Floating point type; float DOUBLE decimal.
3. Date and time type; year time date datetime timestamp.
4. Text string; char varchar tinytxet text mediumtext longtext enum set.
mysql function
abs() sqrt() ceil() ceiling() floor() rand() round()
Query data and insert, update and delete
Create database table: create database database name;
Open the database: use database name;
Create a new data table: create table name (field name data type);
{
Data type: string type, numeric type, date and time type
1. Integer type; tinyint smallint mediumint int bigint.
2. Floating point type; float DOUBLE decimal.
3. Date time type; year time date datetime timestamp.
4. Text string; char varchar tinytxet text mediumtext longtext enum set .
Constraints: primary key primary key
unique primary key unique
non-null constraint not null
default constraint default default value
foreign key constraint foreign key name foreign key (field name) references primary key name Primary key column;
# Modify field name alter table table name change field name new field name data type
Modify data type alter table table name modify field name data type
Add field alter table table name add field name data type (first /after)
Delete Field Alter Table Table Drop field Name
Storage engine Alter Table Table Name Engine = Storage Engine to Delete the outer key to restrain the table name Drop Foreign Key outer key. Field name from table name ( where 1. Field = table name 2. Field;
Left join select field name from Table name 1 left outer join Table name 2 on Table name 1. Field = table name 2. Field;
Right join select field name from Table name 1 right outer join Table name 2 on Table name 1. Field = Table name 2. Field;
* The left join is the field to be queried. The result includes all the fields of the left table
Subquery (nested query) ( any(some)
exists (exists is used together with conditional expressions. If the query statement after exists returns at least one record,
then the exists result is true. At this time, the outer query statement will query, and not exists is the opposite.)
in )
Merge query results select field name from table name query condition union (all) select field name from table name query condition
Note: The number of columns and field names corresponding to the two tables must be equal. Not using all results in deleting duplicate records.
]
}
Insert into data table: insert into table name (field name) values (data to be inserted);
Update data: updata table name set field = value condition;
Delete Data: delete from table name condition;
Index
Advantages: Create a unique index to ensure the uniqueness of each row of data in the database table, greatly speeding up query speed, and in terms of referential integrity of event data, you can Accelerate the connection between tables
Using grouping and sorting clauses for data query can also reduce the time of grouping and sorting in the query.
Ordinary index index (field name): The most basic index type, without uniqueness restrictions, just to speed up access to data
Unique index unique idenx Index name (field) The index value must be unique. However, null values are allowed to reduce the execution time of query summary operations, especially for huge data tables.
Single column index A table can have multiple indexes
Combined index Create an index on multiple fields, follow the leftmost prefix when querying, and the index can only be used when the query matches such a leftmost prefix
Full text index fulltext Can be used for full-text search. Only the MYISAM storage engine supports fulltext index and only char varchar text
Spatial index spatial must be created in a MYISAM type table, and the spatial type field must be empty,
Create an index on an existing table
alter table table name add index index name (field name (index length))
create index index name on table name (field name);
alter table Table name drop index index name;
drop index index name on table name
Create stored procedures and functions
create procedure name of stored procedure () begin stored procedure body end;
Each call will execute the stored procedure body.
Create stored function
create stored function name (parameter list)
returns return value type
return (function body);
Use of variables
Define variables :declare variable name variable type default default value;
Assign value to variable: set variable name = value;
Use of cursor
Declare cursor: declare name cursor for for query statement;
Open Cursor: open name;
Use cursor: fetch name into Save the result queried in the cursor into the parameter;
Close the cursor; close name;
Use of process control (case loop leave iterate repeat while )
Call the stored procedure: call name (parameter);
Call the stored function: select name (parameter);
View
The meaning of the view: A view is a virtual table, which is a table exported from one or more tables in the database.
create [or replace] view view name as select statement
create view view name (self-defined column name) as select Statement
desc view name;
show create view view name\G
show table status like 'view name'\G
Modifying the view is the same as creating the view.
alter view view name as select statement
updata view name set field = value;
delete view drop view if exists view name;
MYSQL trigger Trigger
Like stored procedures, they are both programs embedded in mysql. Triggers trigger an operation based on time. These events include insert update delete
Create trigger
Create only one Trigger for executing the statement
create trigger trigger name identifies the triggering time (before/after) identifies the triggering event (insert update delete) on identifies the table name of the trigger for each trigger execution statement;
This article Explained the related content of mysql, please pay attention to php Chinese website for more content.
Related recommendations:
MySQL database multi-table operation
MySQL database single table query
The above is the detailed content of MYSQL study notes. For more information, please follow other related articles on the PHP Chinese website!

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment