This is the 10th day of my participation in the August More Text Challenge. For details, see:August is more challenging
First, the introduction of database
A database is a warehouse used to store data.
1.1 SQL
Structured Query Languages are a language used to operate relational databases. They are the general operating language of relational databases. Common relational databases:
Relational database | Use the language | Development co. |
---|---|---|
access | SQL | Microsoft corp. |
SQL Server | T-SQL | Microsoft corp. |
Oracle | PL/SQL | Oracle corporation |
MySQL | MySQL | Oracle acquisition |
1.2 Connecting to the mysql server on Windows
- You can use Navicat or mysql-front. Here I’m using Navicat, as shown below:
Connect to mysql using Navicat:
This should be empty by default, this is the database that I tested earlier. Click Connection and select MySQL. The following interface appears:
My initial password is 123456. OK, and you’re ready to connect. As shown in figure:This is the same table that I used to look at some open source projects.
- You can also connect with phpMyadmin, which has been configured before, so let’s open it directly, as follows:
Click execute, as follows:
- Connect through wAMP
As shown in the figure, open MySQL Console.
Appear as shown in figure
Enter your password and press Enter to enter the connection:Mysql > select * from ‘bin’ where ‘bin’ = ‘bin’; mysql > select * from ‘bin’ where ‘bin’ = ‘bin’;
The command | Command meaning |
---|---|
-h | host |
-p | port |
-u | user |
-p | password |
Enter the following names: | |
The connection is successful and you can write some mysql statements to query. | |
If you connect to a local database,-h You can omit it. If the port number is 3306, the port number-P You can also omit, useexit orquit or\q Command to exit: |
|
Next type the omitted command: | |
That’s okay, too. |
- Ciphertext connection via command line:
Two, the basic concept and operation of the database
2.1 Basic Concepts of the Database
- Database: A database stores tables. A database can store multiple tables
- Table: used to store data
- Relationship: A common field for two tables
- Line: also known as record, also known as entity
- Column: also called field, also called attribute
In terms of table structure, tables are divided into rows and columns; In terms of table data, the table is divided into records and fields; In object-oriented terms, a record is an entity and a field is an attribute.
Database execution process:
2.2 Database Operations
Open the terminal command line and connect to the database:
2.2.1 Viewing the Database
To view all databases: show databases;
2.2.2 Creating a Database
Create database:Create Database Database name
:
An error occurs when creating an existing database:When creating a database, determine whether the database exists, create it only if it does not exist, syntax:Create database if Not EXISTS Database name;
Special characters, keywords for database name:You can see the error. If you want to use special characters or keywords for the database name, you can use ·· Enclose the database name:
When creating the database, specify the encoding. If not specified, the installation encoding will be usedshow variables like 'character_set_%';
:You can specify the database code when creating a data database. Syntax:create database emp charset=utf8;
The database is stored in the data folder:You can also change the save address of the database in the my.ini configuration file:Set the character set and proofread set for the database in the db.opt file:
2.2.3 Deleting a Database
Grammar:Drop Database if exists Data name;
2.2.4 Displaying database creation information
Grammar:show create database emp;
2.2.3 Modifying the Database
When you change a database, you can only change the database options, and the database options only have character encoding. grammarAlter database database name charset= character encoding;
2.2.4 Using the Database
Syntax: use database name;
On the way to learning MySQL, if you find this article helpful to you, then please focus on like and comment 3 times, thank you, your must be another support of my blog.