创建数据库及授权
创建数据库sql语句
drop database if exists `test-pro`;
create database `test-pro` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
创建新用户并授权指定数据库权限
- 使用 root 管理员登陆 mysql
mysql -uroot -p123456;
- 创建用户
-- 低版本数据库
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 访问
- 修改密码(可选)
alter user '用户名'@'%' identified by '密码';
-- 示例
alter user 'test'@'%' identified by 'test123'
- 给该用户添加权限
-- 指定数据库
grant all privileges on 想授权的数据库.* to '用户名'@'%';
-- 全部数据库
grant all privileges on *.* to '用户名'@'%';
-- 示例
grant all privileges on test_table.* to 'test'@'%';
- 刷新使生效
flush privileges;
- 删除用户
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`;
创建表
见博客