怎样修改MySQL中遗失的“ROOT“用户密码

假如忘记了MySQL的root密码,大家可以用以下方法重新设置:

◆1. KILL掉系统里的MySQL进程

◆2. 用以下命令启动MySQL,以不检查权限的方式启动

mysqld_safe --skip-grant-tables &

◆3. 然后用空密码方式使用root用户登录 MySQL

mysql -u root

◆4. 修改root用户的密码

mysql> update mysql.user set password=PASSWORD('新密码')
where   User='root';

mysql> flush privileges;

mysql> quit

◆5. 重新启动MySQL 


-------------------------------------------------------

--创建用户举例:

GRANT SELECT , INSERT , UPDATE , DELETE , CREATE ,DROP , FILE , INDEX , ALTER , CREATE TEMPORARY TABLES, EXECUTE,ALTER ROUTINE,CREATE ROUTINE ON *.* TO 'admin'@'%'
IDENTIFIED BY 'adminpasswd'
WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 ;

GRANT SELECT , INSERT , UPDATE , DELETE , CREATE ,  INDEX , CREATE TEMPORARY TABLES, EXECUTE ON cdrenruidb.* TO 'user'@'%'
IDENTIFIED BY 'userpasswd'
WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 ;


--删除用户
REVOKE ALL PRIVILEGES ON * . * FROM 'user'@ '%';
DROP USER 'user'@ '%';
DROP DATABASE IF EXISTS 'user' ;

你可能感兴趣的:(mysql,user,password)