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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

mysql whether to change table lock table mysql whether to change table lock table Apr 08, 2025 pm 05:06 PM

When MySQL modifys table structure, metadata locks are usually used, which may cause the table to be locked. To reduce the impact of locks, the following measures can be taken: 1. Keep tables available with online DDL; 2. Perform complex modifications in batches; 3. Operate during small or off-peak periods; 4. Use PT-OSC tools to achieve finer control.

Unable to log in to mysql as root Unable to log in to mysql as root Apr 08, 2025 pm 04:54 PM

The main reasons why you cannot log in to MySQL as root are permission problems, configuration file errors, password inconsistent, socket file problems, or firewall interception. The solution includes: check whether the bind-address parameter in the configuration file is configured correctly. Check whether the root user permissions have been modified or deleted and reset. Verify that the password is accurate, including case and special characters. Check socket file permission settings and paths. Check that the firewall blocks connections to the MySQL server.

RDS MySQL integration with Redshift zero ETL RDS MySQL integration with Redshift zero ETL Apr 08, 2025 pm 07:06 PM

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

Query optimization in MySQL is essential for improving database performance, especially when dealing with large data sets Query optimization in MySQL is essential for improving database performance, especially when dealing with large data sets Apr 08, 2025 pm 07:12 PM

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

Can mysql handle multiple connections Can mysql handle multiple connections Apr 08, 2025 pm 03:51 PM

MySQL can handle multiple concurrent connections and use multi-threading/multi-processing to assign independent execution environments to each client request to ensure that they are not disturbed. However, the number of concurrent connections is affected by system resources, MySQL configuration, query performance, storage engine and network environment. Optimization requires consideration of many factors such as code level (writing efficient SQL), configuration level (adjusting max_connections), hardware level (improving server configuration).

Can mysql run on android Can mysql run on android Apr 08, 2025 pm 05:03 PM

MySQL cannot run directly on Android, but it can be implemented indirectly by using the following methods: using the lightweight database SQLite, which is built on the Android system, does not require a separate server, and has a small resource usage, which is very suitable for mobile device applications. Remotely connect to the MySQL server and connect to the MySQL database on the remote server through the network for data reading and writing, but there are disadvantages such as strong network dependencies, security issues and server costs.

Do mysql need to pay Do mysql need to pay Apr 08, 2025 pm 05:36 PM

MySQL has a free community version and a paid enterprise version. The community version can be used and modified for free, but the support is limited and is suitable for applications with low stability requirements and strong technical capabilities. The Enterprise Edition provides comprehensive commercial support for applications that require a stable, reliable, high-performance database and willing to pay for support. Factors considered when choosing a version include application criticality, budgeting, and technical skills. There is no perfect option, only the most suitable option, and you need to choose carefully according to the specific situation.

How to optimize MySQL performance for high-load applications? How to optimize MySQL performance for high-load applications? Apr 08, 2025 pm 06:03 PM

MySQL database performance optimization guide In resource-intensive applications, MySQL database plays a crucial role and is responsible for managing massive transactions. However, as the scale of application expands, database performance bottlenecks often become a constraint. This article will explore a series of effective MySQL performance optimization strategies to ensure that your application remains efficient and responsive under high loads. We will combine actual cases to explain in-depth key technologies such as indexing, query optimization, database design and caching. 1. Database architecture design and optimized database architecture is the cornerstone of MySQL performance optimization. Here are some core principles: Selecting the right data type and selecting the smallest data type that meets the needs can not only save storage space, but also improve data processing speed.

See all articles