Home > Database > Mysql Tutorial > body text

Linux database mysql installation

WBOY
Release: 2023-05-08 20:15:06
Original
410 people have browsed it

In the modern Internet era, the role of the database is self-evident. It is the cornerstone of a website or application. Among them, MySQL, as a free, open source, reliable, fast and efficient database management system, is widely used in all walks of life on the Internet. This article will introduce how to install MySQL database on Linux system.

Step 1. Prepare the environment before installation

Before starting the installation, we need to check whether MySQL has been installed in the system. Enter the following command in the terminal:

mysql --version
Copy after login

If MySQL has been installed on the system, the MySQL version information will be output.

If you have confirmed that MySQL is not installed, you need to download the MySQL software package first. You can go to the MySQL official website (https://dev.mysql.com/downloads/mysql/) to download the corresponding version. This time I am using MySQL version 8.0.

Step 2. Install MySQL

First, we need to use the terminal to log in to the root account. Then, execute the following command:

sudo apt-get update
Copy after login

This command is to update your system packages.

Next, you need to execute the following command to install MySQL:

sudo apt-get install mysql-server
Copy after login

During the installation process, the system will prompt you to enter the MySQL root account password. Please note that this password needs to be kept secret as it is the credential used to connect to the database.

After the installation is complete, run the following command to start the MySQL service:

sudo service mysql start
Copy after login

At this time, the MySQL service is running normally.

Step 3. Configure MySQL

After installing MySQL, we need to perform some configurations. First, we need to set a new root account password for MySQL to ensure security. Run the following command in the terminal:

sudo mysql_secure_installation
Copy after login

Then, follow the terminal prompts for the next step, such as asking you to set a new root password, confirm deletion of anonymous users, etc.

Step 4. Connect to MySQL

Now, MySQL has been installed and configured correctly. Next you need to test whether you can connect to the MySQL server.

Enter the following command in the terminal to connect to MySQL:

mysql -u root –p
Copy after login

This command will prompt you for your password. Here, we enter the root account password we set previously.

If you successfully log in to MySQL, it means that we have successfully installed the MySQL database. If any errors occur or login fails, please make sure your root account and password are correct.

Step 5. Operate MySQL in the terminal

The MySQL operation commands executed in the terminal are the same as using the MySQL client. Here are some of the most common MySQL terminal commands.

  • Show all databases: show databases;
  • Create a new database: create database databasename;
  • Enter a database: use databasename;
  • Display all tables in the database: show tables;
  • Create a new table: create table tablename;
  • Display all data in the table: select * from tablename;
  • Insert some data: insert into tablename (column1,column2,column3) values ​​(value1,value2,value3);
  • Update data in a table: update tablename set column1=value1 where condition;
  • Delete data in a table: delete from tablename where condition;

Summary

The article on how to install MySQL on a Linux system has been completed. In actual work, MySQL database, as an excellent open source database management system, is favored by more and more enterprises and developers, and upgrading and managing MySQL has also become a skill requirement. I hope this article can help readers who need to learn MySQL.

The above is the detailed content of Linux database mysql installation. 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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!