当前位置:网站首页>Log in and operate the database with the command line
Log in and operate the database with the command line
2022-07-18 08:24:00 【Java Genie】
One 、 Database login and data definition
1、 Log in to the database
Start by opening Mysql In the installation directory bin Catalog , Then enter... In the address field cmd, enter . My is installed in C disc .

Enter the command line interface , And enter the mysql -u root -p, Enter and enter the password , The following screen is displayed , Indicates successful login .
Input 'help' or '\h', view help . Input '\c' Clear the current input statement
Input help after , There is one Note: All statements should be followed by ; end . This point and Navicat The rules in are different . Attention .
So let's get started ~
2、 Query which databases are
show databases;

3、 Create database
create database Database name ;
create database test;

At this time, the database is found test Created successfully . After entering test database
use test

then , There are no tables in our database , So let's create a student table first stu, Containing fields sno ,snames,sage,ssex
4、 Create table
create table stu (
sno char(10) primary key,
sname varchar(25) not null,
sage int,
ssex varchar(2));
Then use show tables; Command query database test All the tables in .
5、 see stu Table structure of table
desc stu;

6、 Modify table structure
① Give the data sheet stu Add fields sdept
alter table stu add sdept varchar(20);

② Delete sdept Field
alter table stu drop sdept;

③ Delete test database
drop database test;

Two 、 Add, delete, change and check the database
Because of our data sheet stu No data yet , So let's talk about how to insert data first
1、 Insert data into
When inserting data , You can have one insert Statement inserts a row , You can have one insert Statement insert multiple lines , Let's demonstrate separately
-- One insert Insert a row
insert into stu values('2021001',' Cao Cao ',23,' male ');
-- One insert Insert multiple rows
insert into stu values('2021002',' Xu Chu ',22,' male '),
('2021003',' Lyu3 bu4 ',25,' male '),
('2021004',' The sable cicada ',24,' Woman ');

After successfully inserting data , We begin to inquire
2、 Data query
Inquire about stu All records in the table
select * from stu;

3、 Data update
Change the age of Cao Cao to 25 year
update stu set sage=25 where sname=' Cao Cao ';

4、 Data deletion
Delete age less than 23 The record of
delete from stu where sage<23;

Not praising is equal to whoring in vain , Not praising is equal to whoring in vain , Not praising is equal to whoring in vain ~
边栏推荐
- Data transmission: Practice of batch extraction of isomorphic and heterogeneous IP data sources
- 蓝鲸配置框架
- What's the use of fftshift? Why does matlab need fftshift after FFT?
- MYSQL和 ORACLE 的常见区别(一)
- (零六)Flask有手就行——配置静态文件
- A-F codeworks round 806 (div.4) A-F problem solution and code
- Torch in pytoch Analysis of nonzero() function
- One question per day · 873 The length of the longest Fibonacci subsequence Mnemonic search
- Software architecture and design (II) -- Architecture Model
- 338. Bit counting · dynamic programming
猜你喜欢

安徽大学标志性建筑

每日一题·735.行星碰撞·栈模拟

競賽·6116·計算布爾二叉樹的值·遞歸

676. Implement a magic dictionary prefix tree

Lifecycle: the foundation of lifecycle aware components - jetpack series (1)

Software architecture and design (I) -- key principles

Openpyxl drawing pie chart

Vscode default new directory overlap

Data transmission: Practice of batch extraction of isomorphic and heterogeneous IP data sources

Today, another chip IPO came out of Shenzhen Huaqiangbei
随机推荐
Qiu Zhao took 6 offers and summarized more than 20 categories of 1100 interview questions, including answer analysis
每日一题·1217.玩筹码·贪心
Anhui University store
J9 Digital Science Popularization: Web3.0 is far away? No, it's already here
This year, how many war investment departments have become "decorations"
From March to June, after summary, more than 200 pages of true question notes and detailed explanations (including core test sites and 6 major factories)
SAR图像:拟合杂波时常用的分布
Matlab:图像增强 imageDataAugmenter() 的用法
Usage analysis of [:, none] in pytoch
Software architecture and design (VIII) -- distributed architecture
Is it true or false that blue collar workers are sleepy and live broadcasting is needed?
LDAP introduction
Software architecture and design (VII) -- interactive architecture
338.比特位计数·动态规划
开发那些事儿:如何解决RK芯片视频处理编解码耗时很长的问题?
Torch in pytoch Max() function analysis
CTSI foundation reserve transparency report - July 2022
Matlab: usage of reading imagedatastore() from dataset
Pytoch distributed training
秋招拿了6offer,总结了20多类1100道面试题含答案解析