解决MySQL安装的版本不同;
解决mysql 安装的 版本不同 ;
1、登录mysql
mysql -u root(用户名) -p
2、输入密码: root
root 自己设置的密码
3、show databases 显示信息;
show databases
4、select user,plugin from mysql. user; 进入mysql内
select user,plugin from mysql. user;
5、ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘密码’;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
6、flush privileges; 刷新数据库;
flush privileges;
7、 \q 退出 重启;
\q
8、show database;
show database;
mysql 一些常用的命令;
创建数据库
MySQL->CREATE DATABASE dbname;
选择数据库
MySQL->USE dbname;
创建表
MySQL->CREATE TABLE tablename;
显示数据库信息,有那些可用的数据库。
MySQL->SHOW DATABASES;
显示表信息,有那些可用的表
MySQL->SHOW TABLES;
显示创建的表的信息
MySQL->DESCRIBE tablename;
增删改查
– 创建数据库 ,
create database 数据库名;
– 删除数据库
drop database <数据库名>;
– create table 表名(字段名称 属性值,字段名称 属性值);
– use Student 指定数据库 , 之后的表不用加前缀; 数据库
– 插入数据; 可以插入多条数据 之间用逗号分隔;
use Student;
insert into result (name,shuxue,chinases,english)values('小灰灰',98,80,100),('小二',60,80,40);
insert into result (name,shuxue,chinases,english)values('张三',50,80,30);
– 修改数据;
– where 查询的条件必须唯一;
update result set shuxue=86 where id=2;
– 删除数据;
– where 查询的条件必须唯一;
– 因为id是唯一的 所以删除后他所占的位置不会被其它占用;
delete from result where id=5;
– 查询数据;
select id,name from result where chinases>60;
– 模糊查询;
select * from result where name like '%小%';
– 排序; 默认升序 ASC 降序 DESC;
select * from result order by id desc;
– 分组;
select * from result where chinases>60 group by chinases;
满足多个条件 之间用 and 隔开;
use student;
– alter 修改;
– 修改表明;
rename table student to stu;
– 添加字段
– 在头添加 first 在某个字段后添加 after 默认添加到最后一个;
alter table stu
add column tel varchar(50)
after sex; -- 在某个字段之后;
-- first; -- 在头部加;
– 把varchar() 可变长度变成固定长度 char()
alter table stu
modify sex char(20)
after id;
– 修改字段; change 要修改的(源)字段 目标字段;
alter table stu
change tel addr varchar(50);
– 删除字段;
alter table stu
drop cls;