Table of Contents
How to start the MySQL service?
There are two ways to connect to the MySQL database :
Navicat for MySQL
Database operation and storage engine
Database: A container that stores database objects.
Commonly used operating commands:
MySQL storage engine
MySQL commonly used column types
表的操作
表的约束(针对于某一列):
Home Database Mysql Tutorial Mysql database quick start basic learning (classic tutorial)

Mysql database quick start basic learning (classic tutorial)

Aug 04, 2018 pm 03:08 PM
mysql

This article is the basic introductory knowledge for learning mysql database, including commonly used operating commands. These knowledge points must be mastered to learn mysql database. Save them to be prepared. First, start the MySQL service, and then connect to the MySQL database. There are two ways. Method 1: Enter the MySQL command line and enter the password in the command line; Method 2: In the run window; details are explained below.

How to start the MySQL service?

How to start the MySQL service? In addition to checking the box to automatically start when booting during installation, you can also run

window (windows) as an example, enter the following:

net start command name: open A service, such as: net start MySQL
net stop Command name: Shut down a server, such as: net stop MySQL

Mysql database quick start basic learning (classic tutorial)

There are two ways to connect to the MySQL database :

Method 1: Enter the MySQL command line and enter the password in the command line;
Method 2: In the running window:
Format: mysql -u account -p password -h The ip of the host where the database server is installed (if it is the local machine, you can use localhost) -P database port
mysql -uroot -padmin -h127.0.0.1 -P3306
The above assumes that my account is root and the password is admin
If the connected database server is on this machine and the port is 3306.
can be abbreviated as: mysql -uroot -padmin

Navicat for MySQL

Navicat for MySQL[1] is actually a visualization tool for MySQL and is a powerful MySQL database management and development tool that provides a powerful enough set of tools for professional developers, yet still easy to learn for new users. Navicat for MySQL is based on the Windows platform and is tailor-made for MySQL, providing a management interface tool similar to MySQL. The emergence of this solution will liberate the brains of PHP, J2EE and other programmers as well as database designers and managers, reduce development costs, and bring higher development efficiency to users.

Database operation and storage engine

Database objects: different structural forms for storing, managing and using data, such as: tables, views, stored procedures, functions, triggers , events, indexes, etc.

Database: A container that stores database objects.

There are two types of databases:
1): System database (the system’s own database): cannot be modified
Information_schema: stores database object information, such as user table information, column information, permissions, characters, partitions and other information.
Performance_schema: stores database server performance parameter information.
Mysql: stores database user permission information.
test: A test database that can be used by any user.

2): User database (user-defined database): Generally, one user database per project.

Commonly used operating commands:

Check which databases exist on the database server:
SHOW DATABASES;
Use the specified database:
USE database_name;
Check which data tables are in the specified database:
SHOW TABLES;
Create a database with the specified name:
CREATE DATABASE database_name;
Delete the database:
DROP DATABASE database_name;

Note:; is required, otherwise it will not be displayed correctly

MySQL storage engine

Data in MySQL is stored using various technologies file (or memory). Each of these technologies uses different storage mechanisms, indexing techniques, locking levels and ultimately provides different functionality and capabilities.
By choosing different technologies, you can gain additional speed or functionality, thereby improving the overall functionality of your application.

MyISAM: has high insertion and query speed, but does not support transactions and foreign keys.
InnoDB: supports transactions, supports foreign keys, supports row-level locking, and has low performance.

The InnoDB storage engine provides transaction safety with commit, rollback, and crash recovery capabilities. However, compared with MyISAM, the processing efficiency is poor and it takes up more disk space to retain data and indexes.

MySQL commonly used column types

The most commonly used integer types:
MySQL column types                                                                                                                                                                                                                      

MySQL commonly used column types#########The most commonly used integer types: ###MySQL column types BIGINT: long/Long###

MySQL 以一个可选的显示宽度指示器的形式对 SQL 标准进行扩展,这样当从数据库检索一个值时,可以把这个值加长到指定的长度。
例如,指定一个字段的类型为 INT(6),就可以保证所包含数字少于 6 个的值从数据库中检索出来时能够自动地用空格填充。
需要注意的是,使用一个宽度指示器不会影响字段的大小和它可以存储的值的范围。一般不用指定位宽。
age  int(2),并不是代表age最多存储99,而是指查询age值得时候使用两个0来占位.

Mysql database quick start basic learning (classic tutorial)

Mysql database quick start basic learning (classic tutorial)

FLOAT[(s,p)]   :
DOUBLE[(s,p)]  : 小数类型,可存放实型和整型 ,精度(p)和范围(s)
                 money double(5,2): 整数和小数一共占5位.其中小数占2位,最大值:999.99,最小-999.99.
                 都不够精确。
定点数据类型: DECIMAL,高精度类型,金额货币优先选择。

MySQL列类型               Java数据类型
FLOAT                        float/Float
DOUBLE                    double/Double
DECIMAL                   BigDecimal

Mysql database quick start basic learning (classic tutorial)

char(size)    定长字符,0 - 255字节,size指N个字符数,若插入字符数超过设定长度,会被截取并警告。
varchar(size)        变长字符,0 - 255字节,从MySQL5开始支持65535个字节,若插入字符数超过设定长度,会被截取并警告。
一般存储大量的字符串,比如文章的纯文本,可以选用TEXT系列类型。
注意:在MySQL中,字符使用单引号引起来。 相当于Java中字符串(String,StringBuilder/StringBuffer);

Mysql database quick start basic learning (classic tutorial)

Mysql database quick start basic learning (classic tutorial)

日期和时间类型为DATETIME、DATE、TIMESTAMP、TIME和YEAR。
注意:在MySQL中,日期时间值使用单引号引起来。 相当于Java中Date,Calender。

Mysql database quick start basic learning (classic tutorial)

BINARY、VARBINARY、TINYBLOB、BLOB、MEDIUMBLOB、LONGBLOB:
存放图形、声音和影像,二进制对象,0-4GB。
但是,在开发中,我们一般存储二进制文件保存路径的路径存储在数据库中。
BIT:我们一般存储0或1,存储是Java中的boolean/Boolean类型的值。

表的操作

1.先进入某一个数据库.(使用USE database_name;命令)
2.输入建表的命令:
CREATE TABLE 表名(
  列名1    列的类型   [约束],
  列名2    列的类型   [约束],
  ….
  列名N    列的类型   约束
);
注意:最后一行没有逗号

若在建表中使用到了数据库的关键字.
比如新建一张订单表:(order),但是order是数据库中的关键字(排序使用).
表名:t_order,若费用使用order这个单词.此时使用反引号()括起来,order`.
一般,起表名为:t_名字。

例子:创建一张表

创建一张学生信息表,记录学生的id,name,age.CREATE  TABLE   `t_student`(         `id `         bigint,         `name `  varchar(20),         ` age `     int);
Copy after login

查看表结构:
DESC table_name;
查看表的详细定义(显示表的定义SQL语句):
SHOW CREATE TABLE table_name;
删除表:
DROP TABLE table_name;

表的约束(针对于某一列):

1.非空约束:NOT NULL,不允许某列的内容为空。
2.设置列的默认值:DEFAULT。
3.唯一约束:UNIQUE,在该表中,该列的内容必须唯一。
4.主键约束:PRIMARY KEY, 非空且唯一。
5.主键自增长:AUTO_INCREMENT,从1开始,步长为1。
6.外键约束:FOREIGN KEY,A表中的外键列. A表中的外键列的值必须参照于B表中的某一列(B表主键)。

Primary key design, uniquely identifies a certain row of data:
1: Single field primary key, single column as the primary key, recommended.
Composite primary key, using multiple columns as the primary key is not recommended.
2: There are two types of primary keys:
1). Natural primary key: use a column with business meaning as the primary key (not recommended), such as ID number;
2). Surrogate primary key: use a column with no business meaning as the primary key (recommended);

Mysql database quick start basic learning (classic tutorial)

Related articles:

Mysql basic command introduction Learning_MySQL

Common operating commands for mysql database study notes_MySQL

Related videos:

Database mysql video tutorial

The above is the detailed content of Mysql database quick start basic learning (classic tutorial). 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)

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

Monitor Redis Droplet with Redis Exporter Service Monitor Redis Droplet with Redis Exporter Service Apr 10, 2025 pm 01:36 PM

Effective monitoring of Redis databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a powerful utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you seamlessly build monitoring solutions. By studying this tutorial, you will achieve fully operational monitoring settings

See all articles