MySQL修改用户密码

  • 修改root密码
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new password');

创建用户并授权

  • 创建用户
-- 用户允许来自所有主机地址的登录
CREATE USER username IDENTIFIED BY 'password';

-- 限制只能在localhost登录
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
  • 授权
GRANT All ON databasename.* TO 'username'@'localhost';

-- 使用%表示来自任何地址的连接
GRANT All ON databasename.* TO 'username'@'%';

-- 授予允许来自所有主机地址,并且对所有数据库的操作权限
GRANT All ON *.* TO 'username'@'%';

-- 授予指定权限
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, GRANT ON *.* TO 'username'@'%';

使用sum时如果没记录不返回null,需要返回0的解决方法

select coalesce(sum(price), 0) as total group by type;