MySQL8.0 在Unix或类Unix系统中重置Root密码
-
登录MySQL Server所安装的用户
可以直接登录,或者su - dsr切换到该用户(dsr是我的MySQL Server安装的用户)
-
停止MySQL服务
sudo find -name *.pid|grep 'mysql'
sudo su
kill `cat /var/lib/mysql/hhw-Precision-7920-Tower.pid`
在本机根目录查找mysql服务pid的存储路径,sudo su是当前用户暂时申请root权限,使用反引号将cat命令的输出替换为kill命令的输入。
Use backticks (not forward quotation marks) with the cat command. These cause the output of cat to be substituted into the kill command. -
新建一个文件,这里假设建立的路径及文件是 /home/me/mysql-init \textit{/home/me/mysql-init} /home/me/mysql-init,输入 ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘MyNewPass’; 作为单独的一行。
touch mysql-init
vim mysql-init
-
使用init_file变量来指定初始化所用的文件
mysqld --init-file=/home/me/mysql-init &
-
启动MySQL服务
service mysql status
service mysql start
关于MySQL8.0 的详细教程,可以参考MySQL8.0 详细教程
参考文献
MySQL 8.0 Reference Manual:Resetting the Root Password: Unix and Unix-Like Systems