首页 > 数据库 > MySQL > MySQL中root用户密码管理
,mysql中root用户密码管理方式主要分为三个场景:
#此方式是给root用户设置临时密码,但应用临时密码登录数据库服务后,需要将临时密码修改,否则不能进行任何操作mysqld --initialize --user=mysql --datadir=/data/3306/data --basedir=/usr/local/mysql# 参数解析# --user:指定Linux系统用户# --datadir:指定数据目录# --basedir:指定按照目录
mysqladmin -uroot password '新密码';#或者 此方法需要登录到MySQL系统中alter user root@'localhost' identified by '新密码';
mysqladmin -uroot password '新密码';#或者 此方法需要登录到MySQL系统中alter user root@'localhost' identified by '新密码';
set password for 'oldboy'@'localhost'=PASSWORD('新密码');flush privileges;
补充:
flush privileges的作用:
此命令只针对授权表中的数据
mysqladmin -uroot -p老密码 password '新密码'#或者登录进数据库中执行alter mysql.user root@'localhost' identified by '新密码';
# 需登录进数据库中update mysql.user set authentication_string=PASSWORD('新密码') where user='root' and host='localhost';flush privileges;
# 需登录进数据库中set password for 'root'@'localhost'=PASSWORD('新密码');flush privileges;www.ctroweLL.com.cn
www.dgruimeng.net
www.tskasiluo.cn
[root@master ~]# /etc/init.d/mysqld stop# 检查是否已关闭[root@master ~]# ps -ef | grep mysqldroot 4070896 4068830 0 15:24 pts/0 00:00:00 grep mysqld
# 输入mysqld_safe --skip-grant-tables --skip-networking & 即可[root@master ~]# mysqld_safe --skip-grant-tables --skip-networking &[1] 4071155[root@master ~]# 2025-10-28T07:25:16.184768Z mysqld_safe Logging to '/var/log/mysql/error.log'.2025-10-28T07:25:16.211299Z mysqld_safe Starting mysqld daemon with databases from /data00/data/mysql
[root@master ~]# 2025-10-28T07:25:16.184768Z mysqld_safe Logging to '/var/log/mysql/error.log'.2025-10-28T07:25:16.211299Z mysqld_safe Starting mysqld daemon with databases from /data00/data/mysql# 输入mysql -uroot 即可mysql -uroot# 修改密码mysql> flush privileges;Query OK, 0 rows affected (0.01 sec) mysql> alter user root@'localhost' identified by 'huangsir';Query OK, 0 rows affected (0.00 sec) mysql> flush privileges;Query OK, 0 rows affected (0.01 sec) # 退出数据库mysql> exit;
# 先杀掉进程[root@master ~]# pkill mysql# 检查进程是否杀掉[root@master ~]# ps -ef | grep mysqlroot 4072026 4068830 0 15:29 pts/0 00:00:00 grep mysql# 启动mysql[root@master ~]# /etc/init.d/mysqld startStarting mysqld (via systemctl): mysqld.service.
[root@master ~]# mysql -uroot -phuangsirmysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 8.0.26 MySQL Community Server - GPLType 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/41450/viewspace-3099047/ ,如需转载,请注明出处,否则将追究法律责任。