mysql创建数据库sql语句、创建新用户授权指定的数据库权限

创建数据库sql语句

drop database if exists `test-pro`;
create database `test-pro` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

创建新用户并授权指定数据库权限

  1. 使用 root 管理员登陆 mysql
mysql -uroot -p123456;
  1. 创建用户
-- 低版本数据库
create user '用户名'@'%' identified by '密码';
-- 高版本数据库
create user '用户名'@'%' identified with mysql_native_password by '密码';
-- 示例1:
create user 'test'@'%' identified with mysql_native_password by '123456';
-- 示例2:
create user 'test'@'localhost' identified with mysql_native_password by '123456';

说明

'%' - 所有情况都能访问
'localhost' - 本机访问
'47.105.144.121' - 指定 ip 访问
  1. 修改密码(可选)
alter user '用户名'@'%' identified by '密码';

-- 示例
alter user 'test'@'%' identified by 'test123'
  1. 给该用户添加权限
-- 指定数据库
grant all privileges on 想授权的数据库.* to '用户名'@'%';
-- 全部数据库
grant all privileges on *.* to '用户名'@'%';
-- 示例
grant all privileges on test_table.* to 'test'@'%';
  1. 刷新使生效
flush privileges;
  1. 删除用户
delete from mysql.user where user='用户名';
-- 示例
delete from mysql.user where user='test'

修改表名sql

RENAME TABLE `原表名` TO `新表名`;
-- 示例:
RENAME TABLE `account_login_record` TO `rd_account_login_record`;

创建表

博客

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值