Table of Contents
This article mainly introduces the basic knowledge of MySQL. Interested friends can refer to it. I hope it will be helpful to everyone.
1. How to start MySql
1. Select "Services" in "Computer Management" and choose to open mysql
2. Use the command line #net start mysql
2. Close MySql method
1. Select "Service" in "Computer Management" and choose to close mysql
2. Use the command line #net stop mysql
3. Log in to the mysql server
1. Log in to MySql, use the command line #mysql -uroot -p123
2. Log out using the command line #exit|quit
4. DDL statement (data definition language)
5.DML statement (data manipulation language)
6.DCL(data controller language)
6.DQL statement (data query language)
Home Database Mysql Tutorial Detailed explanation of the basic knowledge of MySQL

Detailed explanation of the basic knowledge of MySQL

May 16, 2018 pm 03:30 PM
mysql about basic knowledge

This article mainly introduces the basic knowledge of MySQL. Interested friends can refer to it. I hope it will be helpful to everyone.

1. How to start MySql

1. Select "Services" in "Computer Management" and choose to open mysql

2. Use the command line #net start mysql

2. Close MySql method

1. Select "Service" in "Computer Management" and choose to close mysql

2. Use the command line #net stop mysql

3. Log in to the mysql server

1. Log in to MySql, use the command line #mysql -uroot -p123

2. Log out using the command line #exit|quit

4. DDL statement (data definition language)

Data definition language: commonly used to define database objects: libraries, tables, fields. Create, modify, delete libraries and table structures

1.查询数据库
#show databases;
2.切换数据库
#use 数据库名称;
#use test;
3.创建新的数据库
#create database if not exits 数据库名称;
#create database if not exits mydb4;
4.删除数据库
#drop database if exits 数据库名称;
#drop database if exits mydb4;
5,修改数据库编码格式
#alter database 数据库名称 character set 编码格式;
#alter database mydb3 character set utf8;
=======================================
1.创建表
#create table 表名称(列名 列类型,列名 列类型,列名 列类型,列名 列类型);
#create table tb_stu(pid char(20),name varchar(50),age int,gender varchar(1));
2.查看表
#show tables;
3.删除表
#drop table 删除表名称;
#drop table tb_stu1;
4.查看表结构
#desc tb_stu;
=======================================
1.修改之添加列
#alter table 表名称 add(列名称 列类型,列名称 列类型);
#alter table tb_stu add(phone varchar(13),class varchar(5));
2.修改之修改列类型
#alter table 表名称 modify 列名称 新列类型;
#alter table tb_stu modify phone varchar(11)
3.修改之修改列名称
#alter table 表名称 change phone 新列名称 新列类型;
#alter table tb_stu change phone phoneNum varchar(11);
4.修改之删除列
#alter table 表名称 drop 列名称;
#alter table tb_stu drop class;
5.修改之修改表名称
#alter table 表名称 rename to 新表名称;
#alter table tb_stu rename to tb_student;
Copy after login

5.DML statement (data manipulation language)

Data manipulation language: Define database records. Add, delete, and modify table records

1.插入数据
#INSERT INTO tb_student(number,NAME,age,gender,phonenum)VALUES('0001','zhangsan',20,'man','123456789');
2.修改数据
where运算符 = ,!=,>=,<=,BETWEEN...AND,IN(...) OR,AND,IS NULL,NOT#UPDATE tb_student SET number=&#39;0002&#39;,NAME=&#39;lisi&#39; ,
age=age+1 WHERE NAME=&#39;lisi&#39;;#UPDATE tb_student SET age=age+1 WHERE number=&#39;0003&#39; &#39;name&#39;=&#39;wangwu&#39; AND gender is null;
3.删除数据
#DELETE FROM tb_student WHERE number=&#39;0002&#39;;
Copy after login

6.DCL(data controller language)

1.创建新用户
用户只能在指定的IP上登录
#create user 名称@IP identified by &#39;密码&#39;;
用户可以在所有的IP上登录
#create user 用户名@&#39;%&#39; identified by&#39;密码&#39;;
2.给用户授权
#grant all on 数据库名.* to 用户名@IP地址;
3.撤销权限
#revoke delete on 数据库名.* from 用户名@IP地址;
4.查看权限
#show grants for 用户名@IP;
5.删除授权用户
#drop user 用户名@IP;
Copy after login

6.DQL statement (data query language)

Data query language: used Query table records

1.指定列查询
#select number,name from stu;
2.去重查询(重复的只记录一次)
#select distinct age from stu;(年龄相同的只记录一次)
3.列运算
(1)数量类型的列可以做加减乘除运算  
   #select *,salary*1.5 from stu;
  #select name,salary+comm from stu;
  (2)转换null的值(如果comm为空,按0计算)  
  #select salary+ifnull(comm,0) from stu;
  (3)字符串连接  
  #select number,concat(job,&#39;haha&#39;) from stu;
  (4)给列起别名  
  #select number 别名,job 别名 from stu;
4.模糊查询
查询名字为三个字并且是以‘明’结尾#select *from stu where name like &#39;__明&#39;;查询名字中带‘明’的数据
#select *from stu where name like &#39;%明%&#39;;
5.排序
(1).升序(年龄升序)
#select *from stu order by age asc;
(2).降序 (年龄降序)
#select * from stu order by age desc;
(3).多列排序(年龄升序,分数降序)
#select * from stu order by age asc,score desc;
6.聚合函数
(1).查询所有列不全为空的个数
#select count(*) from stu;
(2).查询得分总数
#select sum(score) from stu;
(3).查询平均分数
#select avg(score) from stu;
(4).查询最高分数
#select max(score) from stu;
(5).查询最低分数
#select min(score) from stu;
7.分组查询
按性别分组,查询不同性别的人数
#select gender,count(*) from stu group by gender;
查看不同性别的得分大于60分的人数
#select gender,count(*) from stu where score>60 group by gender;
查看不同性别的得分大于60分并且人数大于30人的分组
#select gender,count(*) from stu where score>60 group by gender having count(*)>30;
8.limit(方言)
#select *from stu limit 4,10;
Copy after login

Related recommendations:

Detailed explanation of steps for PHP MySQL to process high-concurrency locking transactions

Steps for PHP MySQL to implement message queue Detailed explanation

How to check the MySQL version?

The above is the detailed content of Detailed explanation of the basic knowledge of MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1247
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

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.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL for Beginners: Getting Started with Database Management MySQL for Beginners: Getting Started with Database Management Apr 18, 2025 am 12:10 AM

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

Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Apr 18, 2025 am 08:42 AM

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.

See all articles