CREATE USER 'username'@'host' IDENTIFIED BY 'password';
CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '';
CREATE USER 'pig'@'%';
GRANT privileges ON databasename.tablename TO 'username'@'host'
GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
GRANT ALL ON *.* TO 'pig'@'%';
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
SET PASSWORD = PASSWORD("newpassword");
SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456");
RENAME USER <旧用户> TO <新用户>
例如:
RENAME USER 'test1'@'localhost' TO 'testUser1'@'localhost';
REVOKE privilege ON databasename.tablename FROM 'username'@'host';
REVOKE SELECT ON *.* FROM 'test'@'host';
DROP USER 'username'@'host';
grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";
GRANT <ALL|priv1,priv2,.....privn> ON
[object] [IDENTIFIED BY 'password']
[WITH GRANT OPTION];
MAX_QUERIES_PER_HOUR count
MAX_UPDATES_PER_HOUR count
MAX_CONNECTIONS_PER_HOUR count
MAX_USER_CONNECTIONS count
grant all privileges on test.* to test@192.168.10.1 identified by '123';
grant all privileges on test.* to test@192.168.10.1 identified by '123';
grant all privileges on *.* to test@192.168.10.1 identified by '123';
grant all privileges on *.* to john@localhost identified by '123';
flush privileges;
CREATE TABLE `point` (
`id` int(11) NOT NULL,
`uid` int(11) DEFAULT NULL,
`point` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INNER JOIN.....ON.....
SELECT u.id, u.name, p.id, p.uid, p.point
FROM user u INNER JOIN point p
ON u.id = p.uid;
左外连接:是指以左边的表为基准,去匹配右边表的数据。还是刚才的例子,因为用户
信息表 A 和用户积分表 B 中都有用户编码字段,因此它们可以通过该字段实现左外连接,
也就是每一个用户信息表 A 的记录都会去匹配用户积分表 B 中的记录,即便没有对应的数
据,也会展示出来
SELECT u.id, u.name, p.id, p.uid, p.point
FROM user u
LEFT OUTER JOIN point p
ON u.id = p.uid;
是指以右边的表为基准,去匹配左边表的数据。这时候就要用用户积分表 B
的每一条记录去匹配用户信息表 A 的每一条记录了
SELECT u.id, u.name, p.id, p.uid, p.point
FROM user u
RIGHT OUTER JOIN point p
ON u.id = p.uid;
CREATE table employee(
`id` int(10) NOT NULL AUTO_INCREMENT,
`employeeid` int(20) NOT NULL,
`empname` varchar(255) NOT NULL,
`sex` char(10),
`age` int(10),
`data` date,
PRIMARY KEY (`id`)
)ENGINE = INNODB;
INSERT INTO employee VALUES
( 1, 1, '李雷', '男', 21,'2021-01-09'),
( 2, 1, '韩梅', NULL, 21, '2020-02-23'),
( 3, 2, '赵南', '女', 23, '2018-05-17'),
( 4, 3, '周倩', '女', 20, NULL),
( 5, 3, '夏雨', '男', NULL, '2017-09-29');
-- 创建部门表
CREATE TABLE departments(
`dpmid` int(4) NOT NULL AUTO_INCREMENT,
`dpmname` char(16) NOT NULL,
PRIMARY KEY(`dpmid`)
)ENGINE = INNODB;
INSERT INTO departments
VALUES
(1,'研发部'),
(2,'产品部'),
(3,'运营部'),
(4,'财务部');
UPDATE employee
SET sex = '女'
where
empname = '韩梅梅'
UPDATE employee
SET age = 24
WHERE
empname = '夏雨'
UPDATE employee
set data = '2019-07-01'
WHERE
empname = '周倩'
select * from employee where data>'2018-01-01' AND age >20;
SELECT
e.id,e.dpmid,e.empname,e.sex,e.age,e.`data`,d.dpmid,d.dpmname
FROM employee AS e INNER JOIN departments AS d
ON e.dpmid = d.dpmid;
SELECT e.id,e.dpmid,e.empname,e.sex,e.age,e.`data`,d.dpmid,d.dpmname
FROM employee e
LEFT OUTER JOIN departments d
ON e.dpmid = d.dpmid;
SELECT e.id,e.dpmid,e.empname,e.sex,e.age,e.`data`,d.dpmid,d.dpmname
FROM employee e
RIGHT OUTER JOIN departments d
ON e.dpmid = d.dpmid;
SELECT AVG(age),MAX(age),MIN(age) from employee ;
SELECT * from employee
ORDER BY
age DESC ,
`data`;
SELECT empname, age,COUNT(*) FROM employee GROUP BY age;
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/justleavel/article/details/121716339
内容来源于网络,如有侵权,请联系作者删除!
INNER JOIN.....ON.....