mysql基础

mysql启动:mysql  -uroot -pGepoint
Grant all privileges on *.* to epoint@’%’;
其中@后表示访问是本机还是其他,%全部
mysql修改密码:
set password for root@localhost = ' ';
flush privileges:刷新到缓存
mysql远程访问:
mysql  -uroot -pGepoint -h192.168.218.100
-P3306
查询所有用户(账号):
Select user,host from mysql.user;
查询具体用户权限:
show grants for epoint@’%’;
创建用户:
Create user epoint@’%’ identified by ‘Gepoint’;
赋予权限:
Grant all privileges on *.* to epoint@’%’;(赋予所有权限,就是dba)
Grant all privileges on epoint.* to epoint@’%’;(仅赋予epoint数据库的权限)
Flush privileges;(刷新到内存生效)
回收权限:
Revoke all privileges on *.* from epoint@’%’;(回收dba权限)
Revoke all privileges on epoint.* from epoint@’%’;(回收epoint数据库访问权限)
删除epoint用户:
Drop user epoint@’%’;
Mysql执行顺序:select>from>where>group by>having>union>order by>limit

mysql常用数据类型:
Decimal:以字符串存储,不会存在精度丢失的情况。
Int:整型
Varchar,text(大数据):字符串类型
Datatime:日期类型

mysql数据库操作:
创建数据库:create database 数据库名;
显示所有数据库:show databases;
删除数据库:drop database 数据库名;
连接数据库: use 数据库名;
查看当前使用数据库:select database();
当前数据库的表信息: show tables;


mysql表操作:
创建表:create table 表名(列名 类型 约束,列名 类型 约束...);
create table 表名(列名 类型 约束,列名 类型 约束...)ENGINE=InnoDB DEFAULT CHARSET=utf8;
删除表:drop table 表名;
截断表:Truncate table 表名;
修改表名: Rename table 表名 to 新表名;
增加列:alter table 表名 add column 列名 列类型
修改列类型:alter table 表名 modify 列名 新类型
修改列名及类型:alter table 表名 change 老列名 新列名 新类型
删除列:alter table 表名 drop column 列名

约束:
主键约束:primary key
添加主键:
Alter table 表名 ADD primary key(列名);
删除主键:
Alter table 表名 drop primary key(列名);
修改为主键:
Alter table 表名 modify 列名 数据类型 primary key;
外键约束:foreign key
非空约束:not null
唯一约束:unique 
默认约束:default
索引:快速定位想要的数据的位置
唯一索引  unique key
主键索引  primary key
普通索引  key
alter table user drop index `idx_company`
alter table user add index `idx_composition` (`nickname`,`company`);
ALTER TABLE table_name ADD UNIQUE (column_list)
ALTER TABLE table_name ADD PRIMARY KEY (column_list)

Oracle默认不开启事务提交,也就是需要commit才能提交事务
Mysql默认开启自动提交。
开启事务: BEGIN;
禁止自动提交:SET AUTOCOMMIT=0;
提交事务:COMMIT;
回滚事务:ROLLBACK;

函数:
主要作用于一个date或者interval类型中截取特定的部分
extract (
{ year | month | day | hour | minute | second | 某一时区 }
from { date类型值 | interval类型值} )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值