Home > Database > Mysql Tutorial > body text

How to reinstall mysql on linux

PHPz
Release: 2023-04-20 13:33:34
Original
3875 people have browsed it

Installing a MySQL database on a Linux system is a very common task. The MySQL database is open source and supports Structured Query Language (Structured Query Language), also known as SQL. Not only that, MySQL also has many powerful features, such as transaction support, data encryption, data partitioning, and distributed databases.

This article will introduce the process of reinstalling the MySQL database. The following are some corresponding steps:

  1. Uninstall the MySQL database

If you have installed the MySQL database on Linux, you need to uninstall it first. The operation is as follows:

1.1 Check whether MySQL has been installed

You can use the following command to check whether MySQL has been installed on your system:

sudo dpkg --get-selections | grep mysql
Copy after login

1.2 Uninstall MySQL

If you find that MySQL has been installed on the system, you can use the following command to uninstall:

sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
Copy after login

In addition, you can also use the following command:

sudo service mysql stop
sudo killall -9 mysql mysqld_safe mysqld
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-...
Copy after login
  1. Install MySQL database

2.1 Download the MySQL database installation package

You can download the latest version of MySQL from the official website (https://dev.mysql.com/downloads/mysql/), or you can use the following command to download. Please note the replacement version number:

wget https://dev.mysql.com/get/mysql-apt-config_0.8.16-1_all.deb
Copy after login

2.2 Install the MySQL database installation package

After downloading the MySQL database installation package, we need to install it. To do this, use the following command:

sudo dpkg -i mysql-apt-config_0.8.16-1_all.deb
sudo apt-get update
sudo apt-get install mysql-server mysql-client
Copy after login

When you run this command, you will be prompted for a new MySQL password and asked for confirmation. Be sure to keep your password and follow the prompts to complete the installation.

  1. Configuring the MySQL database

3.1 Open the MySQL port

In order for MySQL to accept connections from other computers, the MySQL port needs to be opened in the firewall . On most Linux distributions, the default port is 3306.

To do this, you can use the following command:

sudo ufw allow mysql
Copy after login

3.2 Configuring MySQL

MySQL is a highly customizable database system. Before we do anything, we have to understand how to link to MySQL and start configuring it.

MySQL can be started using the following command:

sudo service mysql start
Copy after login

Once the MySQL server has been started, you can access the MySQL shell console. This can be done using the following command:

mysql -u root -p
Copy after login

When you execute this command, MySQL will ask you for your password. After you enter the correct password, you can access the MySQL console.

In the MySQL console, you can use the SQL language to interact with the server. Here are some basic commands to remember:

  • SHOW DATABASES; Show all databases
  • CREATE DATABASE databasename; Create a New database
  • USE databasename; Connect you to the selected database
  • SHOW tables; Show all data tables
  • CREATE TABLE tablename(column1 data type,column2 datatype, etc); Create a new table
  • SELECT * FROM tablename; Display all data of the table

So far, we have finished all the processes of reinstalling MySQL. In this process, you not only learned to download and install MySQL, but also learned how to open the MySQL port and how to perform some of the most basic settings on MySQL. If you are familiar with MySQL, then you can already install and configure a powerful database on Linux, which will provide unlimited convenience for your work and business.

The above is the detailed content of How to reinstall mysql on linux. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template