修改mysql中root的初始密码

本文详述了在Ubuntu18.04环境中,如何安全地修改MySQL初始的root密码。通过避免在命令行直接输入密码的方式,采用登录MySQL并使用SQL语句来更改密码,确保了密码的安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我的工作环境

  • Ubuntu 18.04
  • mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64) using EditLine wrapper

问题描述

  • 修改mysql初始的root密码时,使用下列语句:

mysqladmin -u root -p password “新密码”

  • 出现警告

mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

  • 查询发现,问题原因在于:

When you run a client program to connect to the MySQL server, it is inadvisableto specify your password in a way that exposes it to discovery by other users.The methods you can use to specify your password when you run client programsare listed here, along with an assessment of the risks of each method. Inshort, the safest methods are to have the client program prompt for thepassword or to specify the password in a properly protected option file.\

  • 总而言之,最开始的命令修改不了root的密码

解决办法

  1. 登录mysql,由于初始密码为空,直接回车就可登录

sudo mysql

  1. 输入

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘新密码’;

  1. 退出mysql

使用ctrl+D 或者键入exit

  1. 重新登录

sudo mysql -uroot -p

  1. 输入新密码,登陆成功。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值