Reset root’s MySQL password

If you have forgotten MYSQL password and need to reset it.

Step-by-step guide

Not the Server root user

A common issue is confusing the Server root user with the MySQL root user.

The Server root user is the server’s main user. The MySQL root user has complete control over MySQL only. The two ‘root’ users are not connected in any way.

Stop MySQL

The first thing to do is stop MySQL. If you are using Ubuntu or Debian the command is as follows:

sudo /etc/init.d/mysql stop

For CentOS, Fedora, and RHEL the command is:

sudo /etc/init.d/mysqld stop

Safe mode

Next we need to start MySQL in safe mode – that is to say, we will start MySQL but skip the user privileges table. Again, note that you will need to have sudo access for these commands so you don’t need to worry about any user being able to reset the MySQL root password:

sudo mysqld_safe --skip-grant-tables &

Note: The ampersand (&) at the end of the command is required.

Login

All we need to do now is to log into MySQL and set the password.

mysql -u root

Note: No password is required at this stage as when we started MySQL we skipped the user privileges table.

Next, instruct MySQL which database to use:

use mysql;

Reset Password

Enter the new password for the root user as follows:

update user set password=PASSWORD("mynewpassword") where User='root';

and finally, flush the privileges:

flush privileges;

Restart

Now the password has been reset, we need to restart MySQL by logging out:

quit

and simply stopping and starting MySQL.

On Ubuntu and Debian:

sudo /etc/init.d/mysql stop
...
sudo /etc/init.d/mysql start

On CentOS and Fedora and RHEL:

sudo /etc/init.d/mysqld stop
...
sudo /etc/init.d/mysql start

Login

Test the new password by logging in:

mysql -u root -p

You will be prompted for your new password.

How to remove / purge MySQL binglos ?

By default, MySQL 5.x and above enables MySQL Binary Log. Keeping MySQL Binary Log will take up a lot of disk space for long run. Older MySQL Binary log can be removed in order to keep your hard disk space free.

MySQL Binary Log stores query event such as add, delete and update in a very details way.

The Binary Log is used for two main purposes:

  1. Replication between master and slave server, statement that has been made on Master server will later send it to slave server.
  2.  Recovery, certain recovery job required data stored in MySQL Binary Log.

Binlogs Location

MySQL binglogs usually stored in mysql root folder, in centos it’s usaully (/var/lib/mysql/) 

To cleanup binary logs on a slave server:

  1. Login to mysql from the command lineshell> mysql -u username -p
  2. To clean binary logs older than a specific date.mysql> PURGE BINARY LOGS BEFORE ‘2018
  3. -12-15 00:00:00′;

Fixing “InnoDB: Error: log file ./ib_logfile0 is of different size” Error

After changing INODDB parameters (at /etc/my.cnf) there might be an error starting MYSQL.

Jun 12 2012

So you wanted to change the value of “innodb_log_file_size” on your mysql server.

As it happens, you can’t just change it the “my.cnf” file, restart and make it work. If you do, Mysql will refuse to start and throw this error instead. You can the details of the startup error in your mysql error log file. 

To safely change this setting follow these steps

Make sure if you are changing things on a production server, you take due care of the mysql downtime due to the changes and restart, and have backups to recover quickly in case something goes wrong.

Step-by-step guide

  1. Shutdown your mysql server, make sure to check the error log that the shutdown had no issues
  2. Move the “ib_logfile0″ and “ib_logfile1″ files from your mysql data directory.
  3. Change “innodb_log_file_size” to your desired setting.
  4. Restart mysql. Check the error log to make sure everything started successfully, mysql may complain that the log files don’t exist, it will make new ones and start.

http://octathorpeweb.com/blog/2012/06/12/fixing-innodb-error-log-file-ib_logfile0-is-of-different-size-error/Error rendering macro ‘contentbylabel’ : parameters should not be empty