Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Complete Guide to Installing and Uninstalling MySQL on Ubuntu and Windows

Tech May 8 3

Uninstalling MySQL on Ubuntu

First, remove MySQL packages:

sudo apt-get remove mysql-*

Then clean up residual configuration files:

dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P

A dialog may appear; select "Yes" to confirm.

Installing MySQL on Ubuntu

You can install MySQL using either of the following commands:

sudo apt-get install mysql-client mysql-server

Or specify a version (e.g., 5.6):

sudo apt-get install mysql-server-5.6

During enstallation, you will be prompted to set a root password. If you did not purge residual data before installation, this prompt may not appear.

Checking MySQL Status

Verify if MySQL is running:

sudo service mysql status

Typically, MySQL starts automatically after installation. If not, start it manually:

sudo service mysql start

If it fails to start, you might encounter the error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'.

Setting the MySQL Root Password

Use the mysqladmin command to set a password:

mysqladmin -u root password 'new-password'

Example:

/usr/bin/mysqladmin -u root password 123456

Resetting a Forgotten MySQL Root Password

  1. Stop the currently runing MySQL process:
/etc/init.d/mysql stop
  1. Start MySQL in safe mode and skip privilege validation:
/usr/bin/mysqld_safe --skip-grant-tables
  1. Open a new terminal and log into MySQL as root:
mysql -u root
  1. Update the root password:
USE mysql;
UPDATE user SET Password = PASSWORD('root') WHERE User = 'root';

If you get error ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE, refer to the solution.

Query OK, 3 rows affected (0.00 sec)

EXIT;
  1. Restart MySQL in normal mode:
/etc/init.d/mysql restart
  1. Verify the new password:
SHOW GRANTS FOR 'root'@'127.0.0.1';
FLUSH PRIVILEGES;
QUIT;

Installing MySQL on Windows (Binary Format)

Refer to the Baidu guide for installation.

Setting the Root Password on Windows

Refer to this CSDN article for setting the password.

Alternatively, use the GRANT command:

GRANT ALL ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456';

Uninstalling MySQL on Windows

Refer to this CSDN article for uninstallation steps.

Installing MySQL 8

Refer to this guide for installing MySQL 8.

Related Articles

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.