LAMP搭建20:MySQL重置root密码

默认情况下安装完成后mysql没设root密码,可以直接登录:

[[email protected] ~]# mysql -uroot

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 5.1.49 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql>

可以使用mysqladmin工具的password选项给root用户添加密码:

[[email protected] ~]# mysqladmin -uroot password ‘654321‘

设置密码后,不输入密码将登陆失败:

[[email protected] ~]# mysql -uroot

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

[[email protected] ~]# mysql -uroot -p654321

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 5.1.49 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql>

重置root密码需要编辑配置文件,加入一条语句:skip-grant:

[[email protected] ~]# vim /etc/my.cnf

……

read_rnd_buffer_size = 4M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size= 16M

# Try number of CPU‘s*2 for thread_concurrency

thread_concurrency = 8

skip-grant

……

重启MySQL

[[email protected] ~]# mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

此时不需要密码即可登录

[[email protected] ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.1.49 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql>

使用mysql库

mysql> use mysql

Database changed

更改user表中root的密码为aming.com

mysql> update user set password=password(‘123456‘) where user=‘root‘;

Query OK, 3 rows affected (0.01 sec)

Rows matched: 3  Changed: 3  Warnings: 0

查看user表中root的信息,\G看起来整洁:

mysql> select * from user where user=‘root‘ \G;

*************************** 1. row ***************************

Host: localhost

User: root

Password: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9

Select_priv: Y

Insert_priv: Y

Update_priv: Y

Delete_priv: Y

Create_priv: Y

Drop_priv: Y

Reload_priv: Y

Shutdown_priv: Y

Process_priv: Y

File_priv: Y

Grant_priv: Y

References_priv: Y

Index_priv: Y

Alter_priv: Y

Show_db_priv: Y

Super_priv: Y

Create_tmp_table_priv: Y

Lock_tables_priv: Y

Execute_priv: Y

Repl_slave_priv: Y

Repl_client_priv: Y

Create_view_priv: Y

Show_view_priv: Y

Create_routine_priv: Y

Alter_routine_priv: Y

Create_user_priv: Y

Event_priv: Y

Trigger_priv: Y

ssl_type:

ssl_cipher:

x509_issuer:

x509_subject:

max_questions: 0

max_updates: 0

max_connections: 0

max_user_connections: 0

……

退出MySQL,编辑配置文件,删除skip-grant行,重启MySQL,再次登录即可使用新密码登录。

[[email protected] ~]# vim /etc/my.cnf

[[email protected] ~]# mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

[[email protected] ~]# mysql

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

[[email protected] ~]# mysql -uroot -p123456

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.1.49 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql>

时间: 2024-10-12 19:58:37

LAMP搭建20:MySQL重置root密码的相关文章

MySQL重置root密码的几种方法(windows+Linux)

重置root密码的方法: windows系统下:1.停止mysql服务:2.新建文件init-root.txt,写上如下内容: update mysql.user set password = password('newpwd') where user = 'root'; flush privileges; 保存:3.打开命令行,输入:C:\mysql\bin\mysqld --init-file=C:\\mysql-init.txt --init-file 选项指向初始化的文件 如果MySQL

MySQL重置root密码

1.重置root密码: service mysql stop# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &# mysql -u root mysqlmysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';mysql> FLUSH PRIVILEGES;mysql> quit # /etc/init.d/m

mysql 重置root密码

最近又项目用到mysql 由于电脑上mysql是很久以前安装的root密码忘记了, 百度一下重置密码 Windows: 1.以系统管理员登陆: 2.停止MySQL服务: 3.进入CMD,进入MySQL的安装目录,假设是D:/MySQL/MySQL Server 5.0/: 4.跳过权限检查启动MySQL, D:/MySQL/MySQL Server 5.0/bin/mysqld-nt --skip-grant-tables 5.重新打开一个CMD,进入D:/MySQL/MySQL Server

MySQL密码忘了怎么办?MySQL重置root密码方法

MySQL有时候忘记了root密码是一件伤感的事.这里提供Windows 和 Linux 下的密码重置方法. Windows: 1.以系统管理员身份登陆系统. 2.打开cmd-----net start 查看mysql是否启动.启动的话就停止net stop mysql. 3.我的mysql安装在d:\usr\local\mysql4\bin下. 4.跳过权限检查启动mysql. d:\usr\local\mysql\bin\mysqld-nt --skip-grant-tables 5.重新打

Mysql重置root密码遇到的坑(忘记密码)

1.原理 通过配置参数"skip_grant_tables"在mysql启动时跳过grant_tables(授权表),从而通过命令来充值root帐号的密码 2.方式 首先需要停止mysql服务 (1)在my.ini文件的[mysqld]块下增加"skip_grant_tables",然后重启mysql服务,再以管理员权限打开cmd执行一些列命令重置密码 步骤如下: A.找到my.ini文件(右击mysql服务找到可执行文件路径,从所在的目录或其它层级目录搜索),在[

MySQL 重置 root 密码

如果密码忘记了我们可以通过以下方法重置密码: 1.在配置文件的 [mysqld] 下添加:skip-grant 2.重启 mysql:/etc/init.d/mysqld restart 3.直接在 CLI 输入 mysql 即可进入 mysql 4.在 mysql 内设置新密码: use mysql; update  user  set  password=password('新密码')  where  user='root'; 5.在配置文件的 [mysqld] 下删除:skip-grant

批处理脚本为Mysql重置root密码(重置密码为123456)

@echo off title mysql ::从注册表找到Mysql的安装路径写入文件mysql.txt reg query HKLM\SYSTEM\ControlSet001\Services\MySQL | find /I "ImagePath">C:\mysql.txt if %errorlevel% neq 0 ( echo MySQL not found pause exit ) ::以”为分隔符,截取第二段内容保存到变量mysqlPath FOR /F tokens

MySQL 修改用户密码及重置root密码

为数据库用户修改密码是DBA比较常见的工作之一.对于MySQL用户账户的密码修改,有几种不同的方式,推荐的方式使用加密函数来修改密码.本文主要描述了通过几种不同的方式来修改用户密码以及mysql root账户密码丢失(重置root密码)的处理方法. 1.密码修改的几种方法 a.可以在创建用户的时候指定密码,以及直接使用grant创建用户的时候指定密码. 对于已经存在的用户直接使用grant方式也可以修改密码 如下: --演示版本 [email protected][(none)]> show v

重置mysql的root密码

在my.ini的段[mysqld]中增加 skip-grant-tables(只增加它即可) 2. 重启mysql服务 3. 打开cmd,转向mysql的安装路径 C:\Program Files\MySQL\MySQL Server 5.1\bin 4. 输入 mysql -uroot -p 5. 密码 输入空,这时会自动转向 sql输入方式 6. 输入 use mysql 7. 输入 update user set password=password('新密码') where user='r