一、报错信息
Re-enter new password:
... Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.
如果一直卡在重复输入密码这一步,新建一个连接窗口,执行命令:
sudo killall -9 mysql_secure_installation
二、手动配置密码
进入mysql终端:
在mysql终端下修改密码:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '输入你的数据库密码';
然后exit,回到终端,重新开始初始化设置:
sudo mysql_secure_installation
-
初始化配置信息 sudo mysql_secure_installation
- VALIDATE PASSWORD COMPONENT.....(使用密码强度校验组件) 输入: n
- New Password:(设置新密码,并重复一遍)
- Remove anonymous users (删除匿名用户) n
- Disallow root login remotely(拒绝远程root账号登录) n
- Remove test database and access to it(移除test数据库) n
- Reload privilege tables now (现在就重新载入权限表) y
如果缺少文件:
【注意路径】需重新下载:wget -O mysql.cnf.example http://exampleconfig.com/static/raw/mysql/ubuntu20.04/etc/mysql/mysql.cnf
修改mysqld.cnf:
//1. 注释"bind-address = 127.0.0.1"
//2. 修改端口号
port = 4417
配置root用户外网访问:
//1. 登陆数据库
sudo mysql -u root -p
//2. 配置
//2.1 选择数据库
use mysql
//2.2 查看账号的主机权限
select user,host from user;
//2.3 host处为localhost时只允许本地使用,改成 % 即可远程使用
update user set host='%' where user='root';
//2.4 刷新缓存
flush privileges;
//2.5 退出mysql
exit;
//3. 重启服务
sudo service mysql restart
//如果需要关闭防火墙
sudo ufw status //inactive为没开
sudo ufw allow 4417 //允许4417端口通过防火墙