mysql 的一些基本操作

3 篇文章 0 订阅

mysql 版本

gg@debian:~/sq$ mysql --version
mysql  Ver 8.0.18 for Linux on x86_64 (MySQL Community Server - GPL)

新建用户
create user 用户名@允许该用户登录的IP identified with mysql_native_password by “密码”;

create user gg@localhost identified with mysql_native_password by "gg";

给用户授权数据库权限

grant all on test.* to gg@localhost with grant option;

gg ->用户
test.* ->test数据库所有表
all ->所有权限

update 某一记录某个字段的值赋值到另一条记录 除了使用联合也可以使用 select 子句

在 update 中使用 select 子句结果

update Product set sale_price=(select x.sale_price+9000 from Product as x where x.product_id=0002) where product_id=0001;

在 MySql 中报错 没有具体研究为什么不行 在 MySql 中 可以再 select 一次避免这个报错
ER_UPDATE_TABLE_USED: You can’t specify target table ‘Product’ for update in FROM clause

update Product
set sale_price=(select y.sale_price+3000 from (select x.sale_price from Product as x where x.product_id=0002) as y)
where product_id=0001;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值