Mysql sql语句

create table `t1` (
	`id` int(11) unsigned not null auto_increment,
	`user_id` int(11) not null default 0 comment'',
	`title` varchar(255) not null default '' comment'',
	`context` text comment'',
	`money` decimal(10,2) not null default 0.00 comment'',
	`status` tinyint(4)	not null default '0' comment'',
	`ctime` int(11) unsigned not null default 0,
	`uptime` int(11) unsigned not null default 0,
	primary key (`id`),
	UNIQUE KEY `title` (`title`) USING BTREE,
	KEY `user_id` (`user_id`) USING BTREE,
	KEY `user_id_join_title` (`user_id`,`title`)
) engine=InnoDB auto_increment=1 default charset=utf8mb4 comment='';
create table `t1` (
	`id` int(11) unsigned not null auto_increment,
	primary key (`id`)
) engine=InnoDB auto_increment=1 default charset=utf8mb4 comment='';
alter table `t1` add column `user_id` int(11) not null default 0 comment'';
alter table `t1` add column `title` varchar(255) not null default '' comment'';
alter table `t1` add column `context` text comment'';
alter table `t1` add column `money` decimal(10,2) not null default 0.00 comment'';
alter table `t1` add column `status` tinyint(4)	not null default '0' comment'';
alter table `t1` add column `ctime` int(11) unsigned not null default 0;
alter table `t1` add column `uptime` int(11) unsigned not null default 0;
alter table `t1` add PRIMARY KEY (`id`)
alter table `t1` add INDEX index_name (`user_id`)
alter table `t1` add UNIQUE (`title`)
alter table `t1` add INDEX index_name (`user_id`,`title`)
alter table `t1` add FULLTEXT (`column`)

下载mysql历史版本

https://downloads.mysql.com/archives/community/

忘记密码

关闭mysql5.7
cd /usr/local/mysql/bin/
sudo ./mysqld_safe --skip-grant-tables
开另一个窗口修改密码
mysql

update mysql.user set authentication_string=PASSWORD(‘123456’) where User=‘root’;
FLUSH PRIVILEGES;
关闭进程
ps -ef|grep mysql

登入

mysql -uroot -h127.0.0.1 -p

修改密码

alter user ‘root’@‘localhost’ identified by ‘Ma123456’;

查看数据库

show databases;

进入数据库

use databases;

查看当前所在数据库下面的所有表

show tables;

查看数据库下面的表的字段

show columns from database.table

grant 授权

grant all privileges on . to root@127.0.0.1 identified by “123456” with grant option;
grant 表示授权 all privileges表示用户可以有所有的权限 on . (.的前面表示什么数据库,后面表示数据库里面的什么表 . 表示所有的数据库里面的所有表)
to 给哪个用户授权 @表示这个用户必须在哪里登录才有这个权限 如有你想给所有ip 那么要使用 root@’%’ identified
在刷新完权限之后要执行 flush privileges; 使他生效
mysql 四种权限 增删查改 select insert update delete

定义存储过程

delimiter $$
create procedure func1()
begin
...
end
$$
delimiter ;

调用存储过程

call func1();

定义触发器

delimiter $$
create trigger add_salary
before insert on employee
for each row
BEGIN
set NEW.salary = NEW.salary + 1000;
end
$$
delimiter ;

查看触发器

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值