Ubantu下安装mysql8.0密码重置

发布时间 2023-07-23 17:27:40作者: kingstoness

ubantu下安装mysql8.0

使用推荐的aptitude来安装,省心省力。

sudo aptitude install mysql-server

无脑“Y“安装成功。

sudo mysql -u root -p

会让你输入密码,密码???什么密码,什么时候有密码了。这种方式安装的貌似没有给设置密码的机会。所以需要重新设置。首先编辑

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

在文件中添加:

skip-grant-tables

这样的目的是跳过密码校验,然后命令重启mySql

sudo service mysql restart
sudo mysql -u root -p #要在管理员的权限下做,然后这次登录就不用输入密码了

进入mysql-clent后:

use mysql;
alter user 'root'@'localhost' identified with mysql_native_password by '新密码';
flush privileges;

这样就可以重置密码了,最后不要忘记将skip-grant-tables注释掉。

BTW

而使用过程中我们不可能直接使用clent来操作数据库,必定是需要依赖工具远程连接的。不要忘记了将连接的限制打开。

use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;

此种方式只适合自己测试玩,如果是生产配置。请使用授权法限制机器的IP连接,此处不加以说明。