当前位置:网站首页>Mysql database operation
Mysql database operation
2022-07-06 03:05:00 【_ half past seven】
Mysql Basic operation
1、 Connect to database
Get into mysql Of bin Enter in the address bar under the directory cmd


Enter the command :
mysql -u root -p
After that “ Enter password: ” A hint of , Enter the password to log in

2、 Displays all databases in the system
Enter the command
show databases;

Most of the sql The commands have semicolons (;) As an end sign
3、 New database abc
command :
create database abc;
After the creation is successful, use the following command to view the results
show databases;

4、 Using a database abc
command :
use abc;
![]()
5、 In the database abc Create a table aaa
command :
create table aaa(id int(10),name varchar(20),username varchar(20),password varchar(20),age int(3));
![]()
6、 Add data to the table
increase 8 Data :
command :
insert into aaa(id,name,username,password,age) values(1,"zhao","111","zhao111",25);
insert into aaa(id,name,username,password,age) values(2,"qian","222","qian222",27);
insert into aaa(id,name,username,password,age) values(3,"sun","333","sun333",24);
insert into aaa(id,name,username,password,age) values(4,"li","444","li444",28);
insert into aaa(id,name,username,password,age) values(5,"zhou","555","zhou555",22);
insert into aaa(id,name,username,password,age) values(6,"wu","666","wu666",29);
insert into aaa(id,name,username,password,age) values(7,"zheng","777","zheng777",20);
insert into aaa(id,name,username,password,age) values(8,"wang","888","wang888",21);

After successful insertion, you can use the following command to view aaa Everything in the table :
select * from aaa;

7、 In the table aaa Delete data from
Delete id=5 The data of , command :
delete from aaa where id=5;
After deleting successfully , View results :

8、 Modify table aaa The data of
modify id=3 The data of , Put it password Set to 123456789, command :
update aaa set password=123456789 where id=3;
After deleting successfully , View results :

9、 Query table aaa Data in
Query all the data
select * from aaa;

Look up id and name Field
select id,name from aaa;

Inquire about name by zhao Of age
select age from aaa where name="zhao";

MySQL Advanced operation
1、order by Usage of
(1) take aaa The data in the table is sorted by age from high to low :
select * from aaa order by age desc;

(2) take aaa The data in the table are based on name From high to low (z-a) Sort :
select * from aaa order by name desc;

2、limit Usage of
The first... In the query table 4 Data
select * from aaa limit 0,4;

From the query table 2 Bar start ,2 Data
select * from aaa limit 2,2;

3、union select Usage of
select * from aaa union select 1,2,3,4,5;
The result of this command is ,select * from aaa Query results and select 1,2,3,4,5 The result of stitching

4、union select combination information_schema database
MySQL5.0 There is a version called information_schema The database of , It stores all the information in the database , It's about MySQL Information about all other databases maintained by the server . Such as database name , Table of database , Data type and access right of table column . and 5.0 There is no .
show databases;
select schema_name from information_schema.schemata;
The result of the two commands is the same , Enter the names of all databases

use abc;
show tables;
select table_name from information_schema.tables where table_schema='abc';
The result of the two commands is the same , It's all output abc Table of database

边栏推荐
- RobotFramework入门(二)appUI自动化之app启动
- 2.12 simulation
- JS regular filtering and adding image prefixes in rich text
- Buuctf question brushing notes - [geek challenge 2019] easysql 1
- My C language learning record (blue bridge) -- on the pointer
- Maturity of master data management (MDM)
- Communication between microservices
- 主数据管理(MDM)的成熟度
- Pat 1084 broken keyboard (20 points) string find
- [Yu Yue education] basic reference materials of digital electronic technology of Xi'an University of Technology
猜你喜欢

Maturity of master data management (MDM)

【 kubernets series】 a Literature Study on the Safe exposure Applications of kubernets Service

【Kubernetes 系列】一文學會Kubernetes Service安全的暴露應用
![[kubernetes series] learn the exposed application of kubernetes service security](/img/61/4564230feeb988886fe595e3125ef4.png)
[kubernetes series] learn the exposed application of kubernetes service security

Sign SSL certificate as Ca

Résumé des méthodes de reconnaissance des caractères ocr

ERA5再分析资料下载攻略

My C language learning record (blue bridge) -- on the pointer

Game theory matlab
![[matlab] access of variables and files](/img/cf/6f3cfdc4310fcf0bdcaa776d68261e.jpg)
[matlab] access of variables and files
随机推荐
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
How to do function test well
【若依(ruoyi)】ztree 自定义图标(iconSkin 属性)
resulttype和resultmap的区别和应用场景
How to read excel, PDF and JSON files in R language?
淘宝焦点图布局实战
A copy can also produce flowers
JS events (add, delete) and delegates
07 单件(Singleton)模式
Apt installation ZABBIX
Technology sharing | what if Undo is too big
07 singleton mode
电机控制反Park变换和反Clarke变换公式推导
C语言sizeof和strlen的区别
1. Dynamic parameters of function: *args, **kwargs
Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?
Web security SQL injection vulnerability (1)
Résumé des méthodes de reconnaissance des caractères ocr
js 正则过滤和增加富文本中图片前缀
Taobao focus map layout practice