
以创建wordpress网站的数据库为例
1、创建数据库
创建可指定字符,或者不指定字符,如果不指定字符,默认为 utf8mb4 和 utf8mb4_0900_ai_ci
2、创建用户
可自行指定用户可访问的IP地址范围。
3、授权用户
4、直接一步到位
或者 这种方法 :创建并授权用户,是二和三的合并。
1、查看数据库
show databases可查询所有存在的数据库
2、查看用户信息
用户信息在系统数据库mysql中的user表中。密码查询不会显示明文密码,而是显示为加密后的密文。
3、查看用户权限
有两种方式查看。
第一种方式 : show grants for 'userwordpress'
第二种方式: select * from mysql.user where user='userwordpress'G
g 相当于’’
G使每个字段打印到单独的行,也有 ’' 的作用
只能查出哪个数据库的哪张表的权限,如查userwordpress在mysql数据库的user表的权限,显示都是N(no),没有权限,如果查root用户就都是Y(yes)选择了。
用drop而非delete,简单的区分就是,drop是删除【表】,truncate与delete则是删除表中【记录】。
删除用户
同理,删除数据库
用drop删除时,会有确认信息,为了防止误删。(删库跑路,请谨慎 *** 作)
你好,如果你使用的是mysql,可以使用grant命令grant select,insert,update,delete,create,drop,alter on 数据库名.* to 数据库名@localhost identified by '密码';
希望你的问题能解决。
登录MySQL[plain] view plain copy print?
mysql -u root -p
添加新用户
允许本地 IP 访问 localhost, 127.0.0.1
[plain] view plain copy print?
create user 'test'@'localhost' identified by '123456'
允许外网 IP 访问
[plain] view plain copy print?
create user 'test'@'%' identified by '123456'
刷新授权
[sql] view plain copy print?
flush privileges
为用户创建数据库
[sql] view plain copy print?
create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci
为新用户分配权限
授予用户通过外网IP对于该数据库的全部权限
[sql] view plain copy print?
grant all privileges on `testdb`.* to 'test'@'%' identified by '123456'
授予用户在本地服务器对该数据库的全部权限
[sql] view plain copy print?
grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456'
刷新权限
[sql] view plain copy print?
flush privileges
退出 root 重新登录
[sql] view plain copy print?
exit
用新帐号 test 重新登录,由于使用的是 % 任意IP连接,所以需要指定外部访问IP
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)