美文网首页
MySQL创建数据库与创建用户以及授权

MySQL创建数据库与创建用户以及授权

作者: mytao4032 | 来源:发表于2021-11-07 17:48 被阅读0次

    原文连接: https://blog.csdn.net/weixin_38898423/article/details/103473895
    在宿主机登陆mysql

    mysql -uroot -h 127.0.0.1 -p
    pwd: root
    
    mysql> show databases;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    mysql> 
    mysql> ALTER USER USER() IDENTIFIED BY 'root';
    

    原文连接:https://www.cnblogs.com/linjiqin/p/10481636.html

    MySQL创建数据库与创建用户以及授权

    1、采用create schema和create database创建数据库的效果一样。

    create schema [数据库名称] default character set utf8 collate utf8_general_ci;--创建数据库
    如:
    create schema mytao default character set utf8 collate utf8_general_ci;
    

    2、密码8位以上,包括:大写字母、小写字母、数字、特殊字符
    %:匹配所有主机,该地方还可以设置成‘localhost’,代表只能本地访问,例如root账户默认为‘localhost‘

    create user '[用户名称]'@'%' identified by '[用户密码]';--创建用户
    如:
    create user 'mytao'@'%' identified by 'mytao';
    

    3、*代表整个数据库

    grant select,insert,update,delete,create on [数据库名称].* to [用户名称];--用户授权数据库
    如:
    grant select,insert,update,delete,create on mytao.* to mytao;
    

    4、flush privileges ;--立即启用修改

    删除动作

    5、revoke all on . from tester;--取消用户所有数据库(表)的所有权限
    6、delete from mysql.user where user='tester';--删除用户
    7、drop database [schema名称|数据库名称];--删除数据库
    8、flush privileges;--立即启用修改

    相关文章

      网友评论

          本文标题:MySQL创建数据库与创建用户以及授权

          本文链接:https://www.haomeiwen.com/subject/ijiezltx.html