删除mysql的root用户恢复方法
1、# service mysqld stop #停止mysql数据库服务
Shutting down MySQL.. SUCCESS!
2、# service mysqld start --skip-grant-tables #跳过授权表启动mysql数据库服务(注:参数--skip-grant-tables为跳过授权表)
Starting MySQL.... SUCCESS!
3、# mysql -p #进入mysql数据库添加root用户并授权
Enter password: #此处直接回车,不用输密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26-log Source distribution
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host,user from user;
+----------+-------+
| host | user |
+----------+-------+
| 10.0.0.% | nginx |
| 10.0.0.0 | nginx |
+----------+-------+
2 rows in set (0.03 sec)
mysql> update user set password=password("new_password") where user="root";
Query OK, 0 rows affected (0.16 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> insert into user set user='root',ssl_cipher='',x509_issuer='',x509_subject=''; #插入root用户
Query OK, 1 row affected (0.03 sec)
mysql> select host,user from user; #查询添加root用户是否成功
+----------+-------+
| host | user |
+----------+-------+
| | root |
| 10.0.0.% | nginx |
| 10.0.0.0 | nginx |
+----------+-------+
3 rows in set (0.00 sec)
mysql> update user set Host='localhost',select_priv='y', insert_priv='y',update_priv='y',Alter_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',create_user_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' where user='root'; #更新root用户权限
Query OK, 1 row affected (0.12 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> exit
Bye
4、# service mysqld restart #重新启动mysql数据库
Shutting down MySQL.. SUCCESS!
Starting MySQL..... SUCCESS!
5、# mysql_secure_installation #进入mysql数据库设置root用户密码
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y #此处询问是否修改root用户密码,输入"y"后回车,给前面添加的root用户设置密码
New password:
Re-enter new password:
Password updated successfully! #提示root用户密码修改成功
Reloading privilege tables..
... Success!
#以下为mysql数据库的一些安全优化
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
6、验证前面5步操作是否有效
# mysql -uroot -p #此时不输入正确的root用户密码,已经提示错误,不能登录
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# mysql -uroot -p
Enter password: #再次输入正确的root用户密码后,进入数据库,代表root用户添加成功,并成功修改密码,如下所示:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.6.26-log Source distribution
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
| blog |
| mysql |
| performance_schema |
| www |
+--------------------+
6 rows in set (0.08 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host,user from user;
+-----------+-------+
| host | user |
+-----------+-------+
| 10.0.0.% | nginx |
| 10.0.0.0 | nginx |
| localhost | root | #代表root用户添加成功
+-----------+-------+
3 rows in set (0.00 sec)
mysql> exit
Bye
删除mysql的root用户恢复方法的更多相关文章
- 删除mysql中root用户恢复方法
1.# service mysqld stop #停止mysql数据库服务 2.# service mysqld start --skip-grant-tables #跳过授权表启动mysql数据库 ...
- Mac下新安装的MySQL无法登陆root用户解决方法
一 设置MySQL命令行搜索路径 0.苹果->系统偏好设置->最下边点mysql 在弹出页面中 启动mysql服务 1.打开终端,输入: sudo vi ~/.bash_profile ...
- MySQL误删root用户导致无法登陆解决方法
测试环境 删除前 mysql> select user,host,password from mysql.user; +------+-----------+---------------- ...
- mysql误删root用户或者忘记root密码解决方法
解决方法一: 到其他安装了Mysql的服务器(前提是要知道该服务器上Mysql的root用户密 码),打开[Mysql的安装目录/var/mysql],将其中的user.frm.user.MYD.us ...
- 忘记Mysql的root用户密码处理方法(以mysql 5.5.33为例)
1.修改mysql服务器的脚本 ~]#vi /etc/rc.d/init.d/mysqld #找到$bindir/mysqld_safe --datadir="$datadir" ...
- MySQL重置root用户密码的方法
本教程适用于采用Win2003.WinXP操作系统的迅美VPS和云主机产品. 当管理员忘记MySQL密码怎么办?屡次输入密码,仍然提示错误,网站无法正常运行,数据库也无法管理,管理员束手无策. 网站程 ...
- MySQL重置root用户密码的方法(转)
本教程适用于采用Win2003.WinXP操作系统的迅美VPS和云主机产品. 当管理员忘记MySQL密码怎么办?屡次输入密码,仍然提示错误,网站无法正常运行,数据库也无法管理,管理员束手无策. 网站程 ...
- Mysql修改root用户密码 For Mac 报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
环境 Mysql版本:5.7.12 操作系统:OSX 10.11 安装文件:.dmg文件 MySQL:mysql-5.7.12-osx10.11-x86_64.dmg(注意5.7跟之前的字段有些不同, ...
- MysqL的root用户不允许远程连接
原文:MysqL的root用户不允许远程连接 今天程序报了异常:java.sql.SQLException: Access denied for user 'root'@'RJB-Z' (using ...
随机推荐
- 【Shell脚本学习8】Shell特殊变量:Shell $0, $#, $*, $@, $?, $$和命令行参数
前面已经讲到,变量名只能包含数字.字母和下划线,因为某些包含其他字符的变量有特殊含义,这样的变量被称为特殊变量. 例如,$ 表示当前Shell进程的ID,即pid,看下面的代码: $echo $$ 运 ...
- Spring-boot & spring.security
spring.security提供了一种身份认证框架,开发者可以在这个框架中实现各种方式的用户身份管理,比如:LDAP.MYSQL.OAUTH.Mongo等等. spring.security认证步骤 ...
- 重构24-Remove Arrowhead Antipattern(去掉箭头反模式)
基于c2的wiki条目.Los Techies的Chris Missal同样也些了一篇关于反模式的post. 简单地说,当你使用大量的嵌套条件判断时,形成了箭头型的代码,这就是箭头反模式(arrow ...
- how to build a paper's architecture?
1. problem? what's the problem? then do some extension of the problem. 2. related works ,which means ...
- python 基础——私有属性
私有属性 python 私有属性以两个下划线开头. python 私有属性只能在类内部访问,类外面访问会出错. python 私有属性之所以不能在外面直接通过名称来访问,其实质是因为 python 做 ...
- zoj 3742 Delivery 好题
Delivery 题目还是自己看吧 - -! 看似图论,实际上是一个考察思维以及数据结构的题. 我们对于先前和向后的边分别进行统计. 对询问离线. 小边按照左端点从大到小排序. 1.对于向后的边,询问 ...
- [转]如何编译tizen源码(图文教程)?
http://blog.csdn.net/flydream0/article/details/9004746 前一篇文章已经介绍了如何下载tizen源码(http://blog.csdn.net/fl ...
- Flex前台和后台WCF服务之间数据的接收与传输
1.首先在flex程序中通过添加webservice,方式是主菜单Data->Connect to WebService,然后输入wsdl文档的地址.如果输入地址后始终添加不进了,或者报错,一般 ...
- Swiper之滑块3
上章Swiper滑块2.Swiper滑块1都是手动的,这章我们来自动的! 其实只是加了Swiper的speed(滑动速度即slider自动滑动开始到结束的时间)属性而已(∩_∩),单位是ms < ...
- Memcached 使用
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...