mysql

作者: IT宝哥哥 | 来源:发表于2020-07-23 16:30 被阅读0次
  1. 创建用户
create user 'username'@'localhost' identified by 'password';//其中localhost是指定可以从哪个主机连接,%代表所有主机都能连接
  1. 给用户分配权限
grant all privileges on www_xxx_cn.* to 'username'@'localhost';//给与所有权限到数据库www_xxx_cn中所有的表;其中username和localhost要和mysql库中user表中(刚刚创建的)一致,否则无法连接
  1. 修改权限后可能需要刷新下
flush privileges;
  1. 有时候提示密码不够安全(not safetiy)ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
show variables like 'validate_password%';//查看全局的变量,见下图
//修改变量
set global validate_password.special_char_count = 0;//取消密码中特殊字符的数量为0
查看全局的变量
  1. 导入数据
mysql -u username -p www_xxx_cn < file.sql;//指定导入文件和数据库,下一步输入密码,若提示密码不安全,看第四条
  1. 导出数据
mysqldump ;//查吧lol
  1. 数据库在本地,网站在docker中,一定记得查询出docker的ipdocker inspect 容器查看(最好绑定IP,不然每次可能会变),并且在上面的所有localhost指定为docker的ip,否则连接不到。注意:在创建的时候如果指定了docker的ip那么就不能用创建的用户来导入了,因为这时我们导入是在localhost导入,所以正确的顺序是: 创建localhost用户 -> 授权localhost -> 导入 -> 修改localhost为docker ip -> 修改授权(grant那一段)-> flush privileges

https://blog.csdn.net/wengzilai/article/details/78871414

  1. 复制数据
create TEMPORARY table tmp SELECT * from user where user="root";
update tmp set host = "%" where user="root";
insert user select * from tmp where user="root";
image.png

相关文章

网友评论

      本文标题:mysql

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