mysql登录密码相关

设置root登录密码

方法一:用root 进入mysql后

mysql>set password =password('你的密码');

mysql>flush privileges;

 

方法二:使用grant语句 

mysql>grant all on *.* to 'root'@'localhost' identified by  '你的密码';

mysql>flush privileges;

 

方法三:进入mysql库修改user表

mysql>use mysql;

mysql>update user set password=password('你的密码')  where user='root'; 

mysql>flush privileges;

 

 

让指定用户能远程登录mysql

方法一:
mysql> create user danny identified by '123';
mysql> use mysql;
mysql> update user set Host='%' where user = 'danny';//让danny可以通过ip访问

登录示例:

mysql  -udanny -p123 -h 192.168.1.1   

给用户赋权
mysql服务器上
用root用户登录赋权;
mysql>grant all on *.* to tom;
mysql> flush privileges;
即可,也可部分赋权。

 

方法二:
在mysql数据库上通过root创建用户并给予权限
mysql>grant all on *.* to 'danny'@'%' identified by '123';
mysql>flush privileges;

注:以上两种方法都不能直接通过localhost在Mysql服务器上实现本地登录,只能通过指定mysql服务器ip登录的方式。如:
[root@Dannyserver opt]# mysql -udanny -p123
ERROR 1045 (28000): Access denied for user 'tom'@'localhost' (using password: YES)

[root@Dannyserver opt]# mysql -udanny -p123 -h12.1.1.1(服务器ip) //这样通过-h指定ip才能登录

 

 

 

记一次docker部署的mysql 5.7 还原旧数据库后登录提示密码错误

原因:数据库全库还原,覆盖了新库的账号密码

解决:

docker exec -it  xxxx bash
vim
/etc/mysql/my.cnf skip-grant-tables
docker restart mysql
mysql
update user set password
=password('xxxx') where user='root'; exit vim /etc/mysql/my.cnf #skip-grant-tables
docker restart mysql
mysql
-u root -p
grant all on
*.* to 'xxx@'localhost' identified by 'xxx';
flush privileges

 

posted @ 2017-12-18 15:02  叮伱格斐呃  阅读(206)  评论(0编辑  收藏  举报
Live2D