[Mysql] Mysql root user accidentally deleted or left with no operating authority of the user how to do

 I. Procedure

1, stop mysql service; mysqld.cnf found in the mysql installation directory; find the following fragment [mysqld] in mysqld.cnf in; join a separate line of code: skip-grant-tables and stored
like me in: / etc / mysql mysqld.cnf /mysql.conf.d files in the directory, modified as follows:

root@c1c5dbe81b37:/etc/mysql/mysql.conf.d# cat mysqld.cnf
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
skip-grant-tables
pid-file    = /var/run/mysqld/mysqld.pid
socket    = /var/run/mysqld/mysqld.sock
datadir    = /var/lib/mysql
#log-error    = /var/log/mysql/error.log
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

 

2, start mysql service, and log

2.1 has the user's

  Login with username and password

2.2 without the user's situation

Direct log (no user name and password) and then the root user
INSERT INTO user (Host, User, Password) VALUES ( 'localhost', 'root', password ( '123456'));

3, root用户设置权限
update user September Host = '%', SELECT_priv = 'y', insert_priv = 'y', update_priv = 'y', Alter_priv = 'y', delete_priv = 'y', create_priv = 'and' , 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 = 'and' show_db_priv = 'and' super_priv = 'and' create_tmp_table_priv = 'and' Lock_tables_priv = 'and' Execute_priv = 'and' repl_slave_priv = 'and' repl_client_priv = 'and' Create_view_priv = ' and 'Show_view_priv =' y ', create_routine_priv =' y ', alter_routine_priv =' y ', create_user_priv =' and 'where user =' root '; commit;

4, put the line mysql.conf.d just added remove and restart the service

5. Finally, you can use the root user login

Second, other relevant command

Authorize the user 
GRANT ALL PRIVILEGES ON * * the TO. ' Root ' @ ' % ' IDENTIFIED BY ' 123456 ' ;
refresh permissions allow it to enter into force flush privileges; see mysql user what
the SELECT the User, Host from the mysql.user;
update user password the UPDATE the mysql.user the SET password
= pASSWORD ( ' 123 ' ) WHERE the uSER = ' the root ' ;
delete user the delete the FROM the mysql.user the Where the user
= ' the root ' and the Host = ' % ';
插入用户 insert into mysql.user(Host,User,Password) values(
"%","root",password("123456"));

 

Guess you like

Origin www.cnblogs.com/756623607-zhang/p/11461548.html