1.自动安装 mysql 后不知道登录密码?

在 ubuntu 下:

1
sudo cat /etc/mysql/debian.cnf

2.密码如何修改?

MySQL 8.0 后 修改密码与之前不同,

8.0 之前修改方式:

1
2
update user set authentication_string=password('123456') 
where user='root' and Host='localhost';

8.0 版本修改方式:

1
alter user 'root'@'localhost' identified by '123456';

修改完后记得刷新:

1
flush privileges;

3.mysql配置文件怎么写?

参考链接:https://www.cnblogs.com/langdashu/p/5889352.html

1
2
3
4
5
6
7
8
vim $HOME/.my.cnf    #注意,文件名为 .my.cnf,不是 .my.conf,手残写错后找了1个小时
#内容:
[client]
password = 123456
#当然,配置文件还可以更多,按照需求写

#登录
mysql -u root

4.MySQL 忘记密码怎么办?

对MySQL5.7有效,其它版本没试过。在Ubuntu系统下。

  1. 停止服务:/etc/init.d/mysql stop
  2. 安全启动,跳过授权表:mysqld_safe –user=mysql –skip-grant-tables –skip-networking &
  3. 登录:mysql -uroot -p 不输入密码进入
  4. 重设密码:参考问题2:密码如何修改
  5. 退出重启:/etc/init.d/mysql restart