Home  >  Article  >  Database  >  Mysql installation under linux

Mysql installation under linux

王林
王林Original
2023-05-08 18:08:372879browse

MySQL installation under Linux

MySQL is an open source relational database management system that is compatible with most operating systems, including Linux. Installing MySQL under Linux allows you to save and process large amounts of data on the server and protect data security. Here we will introduce how to install MySQL on Linux system.

1. Check the Linux version

Before starting to install MySQL, you need to confirm your Linux distribution and version. In order to view this information, you can open a terminal and type the following command:

uname -a
lsb_release -a

This will output your Linux distribution name and version number, as well as the Linux kernel version and computer architecture.

2. Add MySQL Yum source

Most Linux distributions will provide a way to install MySQL through yum. Here we will add MySQL yum source and install MySQL.

1. Download and install the RPM package of the MySQL Yum warehouse from the MySQL official website, enter the following command:

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
sudo rpm -ivh mysql80-community-release-el7-3.noarch.rpm

Please make sure that your operating system version matches the downloaded rpm file. If your system version and the version of the downloaded file do not match, the installation may fail.

2. Before adding the Yum source, first open /etc/yum.repos.d/mysql-community.repo (MySQL’s Yum configuration file) and check whether the parameters of the Yum source are correct:

sudo vi /etc/yum.repos.d/mysql-community.repo

When viewing this configuration file, some important options you want to check are:

  • baseurl: This option contains the URL of the repository where the RPMs files for MySQL must be installed.
  • gpgcheck: This option determines whether yum checks signature files that match the metadata in the RPM package that has been stored in the remote repository. This helps ensure that the package you are installing has not been tampered with or corrupted.
  • enabled: This option determines whether yum should use the RPMs contained in the repository. If it is set to 1, yum will use the RPMs of all matching packages.

Make sure these parameters meet your needs. For example, if you want to install the MySQL Server package, check the "[mysql80-community]" section in the file to make sure "enabled=1".

3. Install MySQL

Use the following command to install the MySQL server:

sudo yum install mysql-server

The yum tool will automatically check all dependencies and download and install MySQL.

3. Start MySQL

After successfully installing the MySQL server, you can run the following command to start MySQL:

sudo systemctl enable mysqld
sudo systemctl start mysqld

This will start the MySQL server and start it every time Start automatically.

4. Set the MySQL root password

By default, the MySQL root password is invalid. In order to improve security protection, it should be set to a strong and unique password. Follow the steps below to set the MySQL root password.

1. Use the following command to log in to MySQL:

sudo mysql -u root

If you see the following error, please use the "-p" option to log in:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'
sudo mysql -u root -p

2. Use the following SQL Statement to set the password for the root user:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Replace "new_password" with the new password you want to set.

3. Download the mysql_secure_installation package and run it using the following command:

sudo yum install -y mysql-secure-installation
sudo mysql_secure_installation

4. The script will guide you to set other MySQL security options, such as disabling anonymous users and remote access.

5. Conclusion

Through the above steps, you have successfully installed and set up the MySQL database under Linux. Now you can start using MySQL to save and process data. During the work process, remember to protect data security and use MySQL properly to make your Linux server more stable and secure.

The above is the detailed content of Mysql installation under linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:mysql character escapeNext article:mysql character escape