Authentication plugin ‘caching_sha2_password’ cannot be loaded
原因: 密码设置太简单
解决办法,登录DB eaver.
运行如下命令 然后修改密码,
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘Java20190713*yy’;
再次登录
创建一个新用户
create user ‘test1’@‘localhost’ identified by ‘Java20190713’;
grant all privileges on . to ‘test1’@‘localhost’ with grant option;
第一个*表示通配数据库,可指定新建用户只可操作的数据库
如:grant all privileges on 数据库.* to ‘test1’@‘localhost’;
第二个*表示通配表,可指定新建用户只可操作的数据库下的某个表
如:grant all privileges on 数据库.指定表名 to ‘test1’@‘localhost’;
准备数据
-- MySQL dump 10.13 Distrib 5.7.12, for Win64 (x86_64)
--
-- Host: localhost Database: java10
-- ------------------------------------------------------
-- Server version 8.0.12
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `student`
--
DROP TABLE IF EXISTS `student`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `student` (
`name` varchar(30) DEFAULT NULL,
`id` int(11) DEFAULT NULL,
`score` double DEFAULT NULL,
`classname` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `student`
--
LOCK TABLES `student` WRITE;
/*!40000 ALTER TABLE `student` DISABLE KEYS */;
INSERT INTO `student` VALUES ('哈哈',1,89,'JAVA10'),('等等',2,54,'JAVA9'),('士大夫',3,34,'JAVA8'),('法国合法',4,99,'JAVA9'),('搜索',5,67,'JAVA8'),('看看',6,78,'JAVA10');
/*!40000 ALTER TABLE `student` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `user`
--
DROP TABLE IF EXISTS `user`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user` (
`name` varchar(30) DEFAULT NULL,
`pwd` varchar(10) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`sex` varchar(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `user`
--
LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` VALUES ('小明','123',18,'男'),('小红','5555',26,'女'),('小张','999',17,'女'),('小刘','993',21,'男'),('小王','992',29,'男'),('小刘','993',21,'男');
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Dumping routines for database 'java10'
--
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-07-13 20:27:20
练习语句
use java10;
-- 对已经存在的表,再添加一个新的列
ALTER TABLE `user` ADD sex varchar(1) NULL;
select * from user;
-- 修改一行数据中的,某一个列的值
update user set name='小王' where pwd='992';
-- 同时修改两个列的值,一次修改多个列,用逗号隔开
update user set age=18,sex='男' where name='小明';
update user set age=16,sex='女' where name='小红';
update user set age=29,sex='男' where name='小王';
-- 查询
select * from user where sex='男' and age>18;
-- 查询结果,只需要名字
select name from user where sex='女' and age>18;
-- 统计男生多少人 count是mysql自带的函数,
-- 表示统计记录条数
select count(*) from user where sex='男';
-- 计算男生的平均年龄
select avg(age) from user where sex='男';
-- 找出整个用户表的 最大的年龄
select max(age) from user;
-- 找出整个用户表的 最小的年龄
select min(age) from user;
select * from user ;
-- 分组查询,分别统计男女人数
select count(*),sex from user group by sex;
-- 取别名,用as, 当然as 也可以不写,用空格代替
select count(*) as '总人数' ,sex '性别' from user group by sex;
select name,pwd from user where name='小刘' and pwd='123';
select * from user where name='小刘' and pwd='993';
select count(*),classname from student group by classname;
select * from student where classname='JAVA10' or classname='JAVA9';