Home > Database > Mysql Tutorial > body text

Install mysql under linux

WBOY
Release: 2023-05-08 09:23:06
Original
4084 people have browsed it

In Linux systems, Mysql is an important and widely used database management system. This article will introduce how to install Mysql under Linux.

1. What you need to know before installation

Before installing Mysql, you need to know the following:

  1. System preparation: You need a Linux server and ensure the system in advance Necessary components are installed in it, such as gcc, make, etc.
  2. Download the installation package locally: Mysql officially provides multiple versions of the installation package, and you can choose the appropriate version according to actual needs.
  3. Installation method: There are many installation methods for Mysql, including binary package installation, yum installation, source code compilation and installation, etc. Here we introduce source code compilation and installation.

2. Download the Mysql installation package

Download the Mysql installation package for Linux from the official website and extract it locally.

3. Install dependency packages

Before installing Mysql in a Linux system, you need to install the following software dependency packages:

sudo yum install cmake
sudo yum install ncurses-devel
sudo yum install bison
sudo yum install gcc-c++
sudo yum install zlib-devel
sudo yum install perl
Copy after login

4. Install Mysql

  1. Enter the decompressed Mysql folder and execute the following command:
sudo cmake .
Copy after login

This statement is to generate a Makefile so that we can compile through the make command.

  1. Execute the make command to compile, as follows:
sudo make
Copy after login

This operation will take a long time, please do not terminate it before it is completed.

  1. Package and install the compiled documents, execute the following command:
sudo make install
Copy after login

This operation will also take some time, please wait patiently.

4. Configure Mysql

The default user name of Mysql is root, and the password is empty; for security reasons, you need to set a new password for it.

  1. Start the Mysql service

After the installation is completed, if you need to start the Mysql service, you need to run the mysql service. Execute the following command in the Mysql directory:

cd /usr/local/mysql/bin/
./mysqld_safe &
Copy after login

This command will start the mysql process service.

  1. Connect to Mysql

Execute the following command to enter the Mysql service:

mysql -uroot
Copy after login

Here -u specifies the user name, and root is the Mysql default user name.

  1. Set a new password

Set a new password and apply:

mysql>UPDATE mysql.user SET password=PASSWORD('yourpassword') WHERE User='root';
mysql>FLUSH PRIVILEGES;
Copy after login

Among them, replace yourpassword with the password you need.

  1. Modify the Mysql configuration file

Find the my.cnf file in the /etc directory and modify it through editing tools such as vi. Below is a sample configuration that you can copy into your my.cnf file.

[client] 
port = 3306 
socket = /tmp/mysql.sock 
default-character-set = utf8

[mysqld] 
port = 3306 
socket = /tmp/mysql.sock 
basedir = /usr/local/mysql 
datadir = /var/mysql 
pid-file = /tmp/mysqld.pid 
user = mysql 
bind-address = 192.168.1.100 
server-id=1 
init-connect='SET NAMES utf8' 
character-set-server = utf8 
skip-character-set-client-handshake 
max_connections=1000 
log-bin = mysql-bin 
binlog-format=ROW 
expire_logs_days = 5 
default-storage-engine = InnoDB 
innodb_file_per_table = 1
Copy after login
  1. Restart the Mysql service

After completing the above configuration, restart the Mysql service:

service mysqld restart
Copy after login

At this point, the installation and configuration of Mysql are completed. Now you can log in using your newly set password and use Mysql.

The above is the detailed content of Install mysql under 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