- 創(chuàng)建用戶
create user 'username'@'localhost' identified by 'password';//其中l(wèi)ocalhost是指定可以從哪個(gè)主機(jī)連接,%代表所有主機(jī)都能連接
- 給用戶分配權(quán)限
grant all privileges on www_xxx_cn.* to 'username'@'localhost';//給與所有權(quán)限到數(shù)據(jù)庫www_xxx_cn中所有的表;其中username和localhost要和mysql庫中user表中(剛剛創(chuàng)建的)一致,否則無法連接
- 修改權(quán)限后可能需要刷新下
flush privileges;
- 有時(shí)候提示密碼不夠安全(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;//取消密碼中特殊字符的數(shù)量為0

查看全局的變量
- 導(dǎo)入數(shù)據(jù)
mysql -u username -p www_xxx_cn < file.sql;//指定導(dǎo)入文件和數(shù)據(jù)庫,下一步輸入密碼,若提示密碼不安全,看第四條
- 導(dǎo)出數(shù)據(jù)
mysqldump ;//查吧lol
- 數(shù)據(jù)庫在本地,網(wǎng)站在docker中,一定記得查詢出docker的ip
docker inspect 容器查看(最好綁定IP,不然每次可能會(huì)變),并且在上面的所有l(wèi)ocalhost指定為docker的ip,否則連接不到。注意:在創(chuàng)建的時(shí)候如果指定了docker的ip那么就不能用創(chuàng)建的用戶來導(dǎo)入了,因?yàn)檫@時(shí)我們導(dǎo)入是在localhost導(dǎo)入,所以正確的順序是:創(chuàng)建localhost用戶 -> 授權(quán)l(xiāng)ocalhost -> 導(dǎo)入 -> 修改localhost為docker ip -> 修改授權(quán)(grant那一段)-> flush privileges,
https://blog.csdn.net/wengzilai/article/details/78871414
- 復(fù)制數(shù)據(jù)
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