Home > Database > Mysql Tutorial > body text

How to install and configure MySQL 5.7 on Linux systems

PHPz
Release: 2023-04-19 15:21:40
Original
1143 people have browsed it

MySQL is a popular database management system that is widely used for data storage and management in many web applications. MySQL 5.7 is the latest version of MySQL, which provides many new features and improvements, such as JSON data type, multi-source replication, and more. In this article, we will explain how to install and configure MySQL 5.7 on a Linux system.

Installation

On Linux systems, there are many ways to install MySQL 5.7. We’ll cover two common ways: using your operating system’s package manager and manual installation.

Install MySQL 5.7 using your operating system's package manager

For most Linux distributions, MySQL 5.7 can be installed through the package manager. The following are the commands to install MySQL 5.7 on different Linux distributions (root privileges are required):

Debian/Ubuntu:

sudo apt-get update
sudo apt-get install mysql-server
Copy after login

Fedora/CentOS/RedHat:

sudo yum update
sudo yum install mysql-server
Copy after login

Arch Linux:

sudo pacman -S mysql
Copy after login

Manual installation of MySQL 5.7

If you want more fine-grained control over the MySQL installation process, you can manually install MySQL 5.7.

Step 1: Download the binary package of MySQL 5.7

You can download the binary package of MySQL 5.7 from the official website. Once downloaded, unzip it into a directory.

Step 2: Install the dependencies of MySQL 5.7

Before installing MySQL 5.7, you need to install some dependencies. In most cases, the following command can install these dependencies:

Debian/Ubuntu:

sudo apt-get install libaio1 libaio-dev libnuma-dev
Copy after login

Fedora/CentOS/RedHat:

sudo yum install libaio libaio-devel numactl-devel
Copy after login

Step 3: Install MySQL 5.7

Install MySQL 5.7 using the following command:

sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql
cd /path/to/mysql
sudo ./bin/mysqld --initialize --user=mysql
sudo ./bin/mysql_ssl_rsa_setup
sudo chown -R root .
sudo chown -R mysql data
sudo chgrp -R mysql .
sudo cp ./support-files/mysql.server /etc/init.d/mysql.server
sudo service mysql.server start
Copy after login

Configuration

After installing MySQL, some configuration is required. The following are some common MySQL configurations:

Change root password

By default, the MySQL root user has no password. For security reasons, a password should be set for the root user.

Use the following command to set the root password:

mysql -u root
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
Copy after login

Replace "yourpassword" with the password you want to set.

Enable remote access

By default, MySQL only allows access on the local host. If you want to access MySQL from another computer, you need to enable remote access.

Use the following command to modify the MySQL configuration file:

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
Copy after login
Copy after login

Find the "bind-address" line and comment it out:

#bind-address            = 127.0.0.1
Copy after login

Save and exit.

Restart MySQL using the following command for the changes to take effect:

sudo service mysql.server restart
Copy after login
Copy after login

Now you can access the MySQL server using the MySQL client from other computers.

Enable logging

MySQL will not log any log information by default. For better management of MySQL, logging should be enabled.

Use the following command to modify the MySQL configuration file:

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
Copy after login
Copy after login

Find the "log_error" and "general_log_file" lines and uncomment them:

log_error=/var/log/mysql/error.log
general_log_file=/var/log/mysql/mysql.log
Copy after login

Save and exit.

Restart MySQL using the following command for the changes to take effect:

sudo service mysql.server restart
Copy after login
Copy after login

Now, MySQL will log error logs and general logs and write them to the /var/log/mysql/ directory.

The following are some basic MySQL installation and configuration steps. To better understand MySQL's configuration options, check out the official documentation for MySQL 5.7.

The above is the detailed content of How to install and configure MySQL 5.7 on Linux systems. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!