Solution to forgetting the root password of self-built MySQL in Alibaba Cloud Linux CentOS 7.2

Solution to forgetting the root password of self-built MySQL in Alibaba Cloud Linux CentOS 7.2

Verification environment:

[root@~~/]# rpm -qa | grep mysql
mysql-5.6.28-1.el6.x86_64
[root@~~/]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.2.1511 (Core)
Release: 7.2.1511
Codename: Core
[root@~~/]# uname -r
3.10.0-327.22.2.el7.x86_64

First, make sure that the server is in a secure state, that is, no one can connect to the MySQL database at will.

Because during the period of resetting the MySQL root password, the MySQL database is completely in a state without password protection, other users can also log in and modify MySQL information at will. You can achieve a quasi-safe state for the server by closing the external port of MySQL and stopping Apache and all user processes. The safest state is to operate on the server console and unplug the network cable.

Modify MySQL login settings:

Add a sentence in the [mysqld] section: skip-grant-tables

[root@~~/]# vi /etc/my.cnf

For example:

[mysqld] 
datadir=/var/lib/mysql 
socket=/var/lib/mysql/mysql.sock 
skip-grant-tables

Save and exit vi.

Restart mysqld

[root@~~/]# /etc/init.d/mysqld restart 
Stopping MySQL: [ OK ] 
Starting MySQL: [ OK ]

Log in and change the MySQL root password

[root@~~/]#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28-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;
mysql> update user set password=password("test") where user='root';
mysql> flush privileges;
mysql> exit; 
Bye

Change the MySQL login settings back

Delete the skip-grant-tables just added to the [mysqld] section, save the file and exit vi;

[root@~~/]# vi /etc/my.cnf

Save and exit vi.

Restart mysqld again

[root@~~/]# /etc/init.d/mysqld restart 
Stopping MySQL: [ OK ] 
Starting MySQL: [ OK ]

Log in with the new password, log in normally

If the database cannot be accessed from the external network, you can do the following:

[root@~~/]# firewall-cmd --permanent --zone=public --add-port=3306/tcp 
success
[root@~~/]# firewall-cmd --reload
success

The above is the solution to the problem of forgetting the root password of self-built MySQL under Alibaba Cloud Linux CentOS 7.2 introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to modify the root password of MySQL in CentOS environment
  • How to reset MySQL root password in Linux (CentOS)
  • How to reset the root password of RHEL7/CentOS7 system
  • How to modify SSH port and disable root remote login in centos 6.5
  • Solve the abnormal problem of running Elasticsearch as root under centos
  • Linux Learning CentOS (Twenty-two)--Enter single-user mode to change the root user's password
  • Solution to the problem of being unable to log in when forgetting to set the root password when installing mysql under CentOS
  • Tutorial on resetting the root password of MySQL under CentOS
  • How to recover MariaDB database root user permissions in centos
  • Solution to forgetting the root password in CentOS 6

<<:  Solution to the inconsistency between crontab execution time and system time

>>:  Detailed explanation of 6 ways of js inheritance

Recommend

How to use Nginx to carry rtmp live server

This time we set up an rtmp live broadcast server...

jQuery realizes the shuttle box function

This article example shares the specific code of ...

HTML 5.1 learning: 14 new features and application examples

Preface As we all know, HTML5 belongs to the Worl...

Summarize how to optimize Nginx performance under high concurrency

Table of contents Features Advantages Installatio...

Do you know what are the ways to jump routes in Vue?

Table of contents The first method: router-link (...

Configure Java development environment in Ubuntu 20.04 LTS

Download the Java Development Kit jdk The downloa...

Detailed explanation of several methods of JS array dimensionality reduction

Dimensionality reduction of two-dimensional array...

WeChat applet implements simple calculator function

WeChat applet: Simple calculator, for your refere...

Examples of vertical grid and progressive line spacing

New Questions Come and go in a hurry. It has been...

Implementation steps for enabling docker remote service link on cloud centos

Here we introduce the centos server with docker i...

Teach you to quickly build a web cluster project based on nginx

Table of contents 1. Project Environment 2. Proje...

Simple writing of MYSQL stored procedures and functions

What is a stored procedure Simply put, it is a se...