Basic concepts of MySql database - connection practice

database
DataBase (database), a warehouse for storing data.
In our previous project, user information was written into a file, and finally a directory users was used to save all user information. The users directory is 
It can be called a database. Use the file system to operate, and often maintain data manually or semi-automatically. Disadvantages: inefficiency.

database management system 
DBMS (database management system). Standalone software for maintaining data operations.
Common DBMSs are:
mysql
oracle
db2 
sqlserver

The concept of database and table
Take MySQL as an example:
We can create several databases in Mysql, each for a project.
Multiple tables can be created in each database, and tables are used to save a set of data.
A data table is made up of rows and columns
The columns are called fields, which are the information of each part of a set of data.
A row is called a record, which is a piece of data composed of various parts of information.

How to operate DBMS
All DBMSs support operations through SQL statements. We send a specific SQL statement to the database to express a certain operation.
SQL has a standard: SQL92
All DBMSs support the SQL92 standard.
Note: Structured Query Language (SQL) structured query language

How to connect to the database
  1. command line form
  2. Graphical interface client provided by the first party or third party (DBeaver, Mariadb)
  3. In the Integrated Development Environment (IDEA)
  4. JDBC (java database connection), if you need to use the database in the java program, connect like this (IDEA uses this method)
Concrete operation

1. Install a graphical interface client (DBeaver or Mariadb)

Baidu DBeaver official website - download the latest - install

2. Connect to mysql database

        a. Database -> New Database Connection -> Select MySQL -> Click Next

        b. Fill in address port, account password. For the account password, see m ysql installation and fill in

3. Create a new database. Right click on the database -> New Database -> Fill in the library name

4. Create a new table, create a new column, save it, and that's it.

5. Operation table, sql editor new table, operation table

6. Specific operation, select the content to execute

Classification of SQL statements
DDL Data Definition Language
CREATE,DROP,ALTER 
A language for manipulating database objects. Database objects are: database, table, view, index, etc.

DML data manipulation language
INSERT,UPDATE,DELETE
A language for manipulating data in tables.

DQL data query language
SELECT 
The language for querying the data in the table.

DCL Data Control Language
The language used by DBAs to manage databases.

TCL Transaction Control Language
COMMIT,ROLLBACK 
Guaranteed atomicity and consistency for DML data operations

Database related operations - practice
建库
1.创建 mydb1和mydb2 数据库 字符集分别为utf8和gbk
CREATE DATABASE mydb1 CHARSET=utf8
CREATE DATABASE mydb2 CHARSET=gbk

2.查询所有数据库检查是否创建成功
SHOW DATABASES

3.检查两个数据库的字符集是否正确
SHOW CREATE DATABASE mydb1
SHOW CREATE DATABASE mydb2

4.先使用mydb2 再使用 mydb1
USE mydb2
USE mydb1

5.删除两个数据库
DROP DATABASE mydb1
DROP DATABASE mydb2



建表
1.创建数据库mydb3 字符集gbk 并使用
CREATE DATABASE mydb3 CHARSET=gbk
USE mydb3

2.创建t_hero英雄表, 有名字和年龄字段
CREATE TABLE t_hero(
name VARCHAR(30),
age INT(3)
)

3.修改表名为hero
RENAME TABLE t_hero TO hero

4.查看表hero的信息
SHOW CREATE TABLE hero

5.查询表hero结构
DESC hero

6.删除表hero
DROP TABLE hero

7.删除数据库mydb3
DROP DATABASE mydb3

 

 Next: Mysql database combat - database building - table building - look up multiple tables

 Create value, happy to share!

Guess you like

Origin blog.csdn.net/ly_xiamu/article/details/128542842