MySQL Operation|Youth Training Camp Notes


theme: condensed-night-purple

highlight: a11y-dark

This is the 14th day of my participation in the "Fifth Youth Training Camp" Companion Notes Creation Activity

Installation Tutorial

https://blog.csdn.net/hellozhangxians/article/details/127169375

operate

Start and shut down the MySQL server

Start: mysqld --console

shutdown: mysqladmin -uroot shutdown

create database

CREATE DATABASE database name;

select database

After you connect to the MySQL database, there may be multiple databases that can be operated, so you need to select the database you want to operate. Select the MySQL database from the command prompt window

A specific database can be easily selected in the mysql> prompt window. You can use SQL commands to select specific databases.use 数据库名;

After executing the above command, subsequent operations will be performed in the specified database.

Create data table

Creating a MySQL data table requires the following information:

表名
表字段名
定义每个表字段

statement:CREATE TABLE table_name (column_name column_type);

js CREATE TABLE IF NOT EXISTS `messege`( `id` INT UNSIGNED AUTO_INCREMENT, `userId` VARCHAR(100) NOT NULL, `content` VARCHAR(40) NOT NULL, `createTime` DATE, PRIMARY KEY ( `id` ) // 主键 )ENGINE=InnoDB DEFAULT CHARSET=utf8;

Analysis: - If you don't want the field to be NULL, you can set the attribute of the field to NOT NULL. If the data entered in the field is NULL when operating the database, an error will be reported. - AUTO_INCREMENT defines the column as an auto-increment attribute, which is generally used for the primary key, and the value will automatically increase by 1. - The PRIMARY KEY keyword is used to define the column as the primary key. You can define a primary key using multiple columns, separated by commas. - ENGINE sets the storage engine, CHARSET sets the encoding.

delete data table

Syntax: DROP TABLE tablename;

query data SELECT

SELECT 列名1,列名2 FROM 表 [WHERE 条件] [LIMIT N][ OFFSET M]

查询语句中你可以使用多个表,表之间使用逗号(,)分割,用WHERE语句来设定查询条件。
SELECT 命令可以读取一条或者多条记录。
星号(*)代替其他字段,SELECT语句会返回表的**所有字段数据**
WHERE 语句包含任何条件。
LIMIT 属性设定返回的记录数。
OFFSET指定SELECT语句开始查询的数据偏移量。默认情况下偏移量为0。

WHERE child clause

In the query statement, the WHERE clause can be used to set the query conditions. Specify any conditions in the WHERE clause. Specify one or more conditions using AND or OR.

It can also be used for SQL DELETE or UPDATE commands.

LIKE clause

WHERE 子句中可以使用等号 = 来设定获取数据的条件, 有时我们需要获取含有指定字符的所有记录,这时可以在 WHERE 子句中使用 SQL LIKE 子句。

LIKE 子句中使用百分号 % 字符来表示任意字符,类似于UNIX或正则表达式中的星号 *。

如果没有使用百分号 %, LIKE 子句与等号 = 的效果是一样的。

也可以在 DELETE 或 UPDATE 命令中使用 WHERE...LIKE 子句来指定条件。

MySQL 排序 ORDER BY

设置查询结果的顺序,默认情况下,按升序排列。

ASC 按升序排列; DESC 按降序排列

Guess you like

Origin blog.csdn.net/weixin_50945128/article/details/129377966