当前位置:网站首页>Various usages of MySQL backup database to create table select and how many days are left
Various usages of MySQL backup database to create table select and how many days are left
2022-07-03 06:15:00 【Bobo AI leaves work】
Command line that must be remembered
mysql -u root -p
mysql -h Host name (192.168.200.1) Fill in the host name you want to link -P 3306 Port number -p
Input password
Accuracy in work use DOUBLE and DECIMAL Do not use float
Start the service
net start mysql
Close the service
net stop mysql
Backup database
stay dos( No MYSQL Next ) To execute under orders -B Represents the entire table
mysqldump -u root -p -B db02 > d:\\bak.sql
mysqldump -u root -p database db02 surface 2 > d:\\bak.sql
Remember to take the path
Recover database ( When entering MYSQL Give orders )
mysql -u -root -p
SOURCE d:\\bak.sql
Delete database
DROP DATABASE db02
Find database elements
SELECT * FROM users WHERE NAME=' Zhang San '
establish MySql surface ( Pay attention to the position of the table )
CREATE TABLE `bobo`(
id INT,
`name` VARCHAR(255),
`password` VARCHAR(255),
`birthday` DATE)
CHARACTER SET utf8 COLLATE utf8_bin ENGINE INNODB;
Create table emp,char There should be characters in it , The difference between characters and bytes
CREATE TABLE `emp`(
id INT,
`name` VARCHAR(32),
sex CHAR(1),
brithday DATE,
entryday DATETIME,
job CHAR(32),
salary FLOAT,
`resume` TEXT) CHARSET utf8 COLLATE utf8_bin ENGINE INNODB;
Write data to the table , Remember to add parameters (id,name,sex,date,datetime,zhiye,sarlary,resume)
INSERT INTO `emp`
VALUES('100',' Tang Bo ',' male ','1996-08-18','2019-11-11 11:12',' The programmer ','5000',
' I am a bobo');
# increase image Column
# View table structure
DESC `emp`
modify job Table properties
# increase image Column
ALTER TABLE `emp` ADD image VARCHAR(32) AFTER RESUME
# View table structure
DESC `emp`
# modify job type by varchar(80) It is not empty by default
ALTER TABLE emp
MODIFY job VARCHAR(80) NOT NULL DEFAULT ''
Delete table attributes
ALTER TABLE emp
DROP brithday;
Modify the name of the table
RENAME TABLE emp TO eeemmppp
Change column names
ALTER TABLE eeemmppp CHANGE `name` `user_name` VARCHAR(50) NOT NULL DEFAULT ''
Update table data
UPDATE eeemmppp SET salary = '9000' WHERE id ='120'
Delete the old monster's record
DELETE FROM eemmpp
WHERE user_name = ' Old monster ';
Various select usage
CREATE TABLE students(
`id` INT NOT NULL DEFAULT 1,
`name` VARCHAR(20) NOT NULL DEFAULT '',
`chinese` FLOAT NOT NULL DEFAULT '0.0',
`english` FLOAT NOT NULL DEFAULT '0.0',
`match` FLOAT NOT NULL DEFAULT '0.0'
);
INSERT INTO students(id,`name`,chinese,english,`match`) VALUES ('1',' Tang Bo ','100','100','100'),
INSERT INTO students(id,`name`,chinese,english,`match`) VALUES ('2',' Zhang Bo ','12','102','104');
SELECT * FROM students
SELECT * FROM students WHERE chinese =100
SELECT `name`,english FROM students WHERE english = 100
SELECT DISTINCT english FROM students
SELECT `name`,(chinese+english+`match`) FROM students
SELECT `name`,(chinese+english+`match`+10) FROM students
SELECT `name` AS ` full name `,(chinese+english+`match`+10) AS total FROM students
How many days are left
SELECT * FROM students
ORDER BY chinese
SELECT `name`,(chinese+english+`match`) AS total FROM students
ORDER BY total DESC
SELECT COUNT(*) FROM students WHERE chinese = 100
SELECT COUNT(*) FROM students WHERE `match` > 100
SELECT SUM(english) FROM students
SELECT SUM(english) AS english,SUM(chinese) AS chinese,SUM(`match`) AS `match` FROM students
SELECT AVG(`match`) FROM students
SELECT AVG(`match`+english+chinese) FROM students
SELECT MAX(`chinese`) FROM students
SELECT MIN(`chinese`) FROM students
# a key
SELECT AVG(`match`),MAX(english) FROM students GROUP BY chinese HAVING chinese > 20、
# How many days have I lived
SELECT DATEDIFF('2021-09-11','1996-08-18') FROM DUAL
SELECT DATEDIFF(NOW(),'1996-08-18') FROM DUAL
# Live to 80 How many days are left in the year old
SELECT DATEDIFF(DATE_ADD('1996-08-18',INTERVAL 80 YEAR),NOW()) FROM DUAL
Create index and query index (UNIQUE Both index and ordinary index can be used ), Delete use DROP
SHOW TABLES
SELECT * FROM students
CREATE UNIQUE INDEX bobo ON students(`name`);
SHOW UNIQUE INDEX FROM students
Show current database
# Display the current user and IP
SELECT USER() FROM DUAL
# Current database
SELECT DATABASE() FROM DUAL
#MD5 encryption
SELECT MD5(' Tang Bo 6768787') FROM DUAL
Capitalize to lowercase
SELECT CONCAT(LCASE(SUBSTRING(ename,1,1)), SUBSTRING(ename,2)) FROM emp
Display name without R Of Everyone's name
SELECT * FROM EMP
where ename not like "%R%"
Display the first three characters of the employee's name
select LEFT(ename,3)
from emp
Write in all capitals A Replace with lowercase a
select replace(ename,"A","a") from emp
Working for more than ten years
select ename,hiredate
from emp
where DATE_ADD(hiredate,INTERVAL 10 YESR)< NOW()
Create a new user format
CREATE USER 'bobo2' @'localhost' IDENTIFIED BY '123456'
bobo2 Change your password set password=password('1234567')
root Changing Bobo's password can succeed
set password for 'bobo2' @ 'localhost'=password('1234567')
root User give bobo2 Permission to view the table
GRANT SELECT,INSERT
ON db02.students
TO 'bobo2' @'localhost'
to bobo2 Modify the permissions
GRANT UPDATE,INSERT
ON db02.students
TO 'bobo2' @'localhost'
To view the user
SELECT * FROM mysql.user
边栏推荐
- YOLOV2学习与总结
- Interesting research on mouse pointer interaction
- 技术管理进阶——你了解成长的全貌吗?
- Introduction to software engineering
- Kubernetes notes (II) pod usage notes
- Naive Bayes in machine learning
- After the Chrome browser is updated, lodop printing cannot be called
- Openresty best practices
- 认识弹性盒子flex
- 表达式的动态解析和计算,Flee用起来真香
猜你喜欢
Kubernetes notes (IV) kubernetes network
CKA certification notes - CKA certification experience post
Bio, NiO, AIO details
ruoyi接口权限校验
Oauth2.0 - explanation of simplified mode, password mode and client mode
Convolution operation in convolution neural network CNN
Detailed explanation of contextclassloader
有意思的鼠標指針交互探究
Oauth2.0 - user defined mode authorization - SMS verification code login
Pytorch builds the simplest version of neural network
随机推荐
YOLOV1学习笔记
项目总结--04
Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
Oracle Database Introduction
Leetcode solution - 01 Two Sum
致即将毕业大学生的一封信
GPS坐标转百度地图坐标的方法
PMP笔记记录
Cesium 点击获三维坐标(经纬度高程)
Svn branch management
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
BeanDefinitionRegistryPostProcessor
In depth analysis of kubernetes controller runtime
Naive Bayes in machine learning
Jackson: what if there is a lack of property- Jackson: What happens if a property is missing?
项目总结--01(接口的增删改查;多线程的使用)
1. Sum of two numbers
Leetcode problem solving summary, constantly updating!
Mysql database
CKA certification notes - CKA certification experience post