我的工作环境
- 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
的密码
解决办法
- 登录
mysql
,由于初始密码为空,直接回车就可登录
sudo mysql
- 输入
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘新密码’;
- 退出
mysql
使用ctrl+D 或者键入exit
- 重新登录
sudo mysql -uroot -p
- 输入新密码,登陆成功。