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:
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
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
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-...
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
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
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.
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
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
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
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 databasesCREATE DATABASE databasename;
Create a New databaseUSE databasename;
Connect you to the selected databaseSHOW tables;
Show all data tablesCREATE TABLE tablename(column1 data type,column2 datatype, etc);
Create a new tableSELECT * FROM tablename;
Display all data of the tableSo 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!