Home > Database > Mysql Tutorial > body text

How to install mysql for linux command

PHPz
Release: 2023-04-19 15:29:25
Original
910 people have browsed it

MySQL is a widely used open source relational database management system. It is currently one of the most popular and widely used database software. MySQL supports multiple operating systems such as Linux, Windows, and Mac OS, and provides a variety of installation methods. This article mainly introduces the steps and precautions for using the command line to install MySQL on the Linux operating system.

1. Preparation before installation
1. Check the kernel version running on the Linux system. The installation version of MySQL needs to be selected according to the corresponding kernel version. You can use the uname command to check the kernel version. The command format is as follows:

$ uname –r
Copy after login

2. Check whether the gcc and make compilation tools are installed. MySQL needs to be compiled and installed using these tools. You can use the following command to check whether it is installed:

$ gcc -v
$ make -v
Copy after login

If it is not installed, you need to use the package manager to install it.

2. Download the MySQL installation package
The MySQL official website provides a variety of installation packages, including RPM, tarball and other formats. You can choose the corresponding installation package according to your own needs. In order to install from the Linux command line, select the installation package in tarball format.

The download address is: https://downloads.mysql.com/archives/community/

3. Decompress the installation package
Use the tar command to decompress the downloaded installation package

$ tar -xzvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
Copy after login

4. Install MySQL
1. Move the extracted MySQL folder to the /opt directory. The command is as follows:

$ sudo mv mysql-5.7.32-linux-glibc2.12-x86_64 /opt/mysql
Copy after login

2. Enter the MySQL directory, create the my.cnf file and open it

$ cd /opt/mysql
$ sudo cp ./support-files/my-default.cnf /etc/my.cnf
$ sudo vim /etc/my.cnf
Copy after login

Enter the following content in the my.cnf file:

[mysqld]
datadir=/var/mysql/data
socket=/tmp/mysql.sock
Copy after login

Description:
datadir: directory used to store database files
socket: pipe for MySQL process communication

3. Create MySQL users and groups
The operation of MySQL requires specific users and groups. Use the following command to create:

$ sudo groupadd mysql
$ sudo useradd -g mysql -M -s /sbin/nologin mysql
$ sudo usermod -d /var/mysql/data mysql
Copy after login

Instructions:
-M: Do not create the user's home directory
-s: Set the shell used after user login
-d: Set the user's home directory

4. Initialize MySQL
Enter the MySQL directory and execute the following command to initialize:

$ sudo ./bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --basedir=/opt/mysql --datadir=/var/mysql/data --initialize-insecure
Copy after login

Description:
--defaults-file: Specify the configuration file path to be used
--user: Specify the user that the MySQL process needs to use
--basedir: Specify the MySQL installation path
--datadir: Specify the directory where MySQL stores data
--initialize-insecure: Do not set the MySQL root password during initialization

5. Start MySQL
Use the following command to start the MySQL service:

$ sudo ./bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
Copy after login

6. Test MySQL
Execute the following command to test whether MySQL is running normally:

$ ./bin/mysqladmin -u root version
Copy after login

If the version information is returned, it means that MySQL is running normally.

5. Summary and Notes
Installing MySQL through the command line requires the use of some Linux command line skills. During the installation process, you need to pay attention to the following points:
1. The installation version of MySQL needs to be selected according to the corresponding kernel version.
2. During installation, you need to check whether the gcc and make compilation tools have been installed.
3. When using the command line to install, you need to prepare the my.cnf file in advance.
4. When initializing, you need to pay attention to specifying the user that the MySQL process needs to use.
5. The startup and testing of MySQL requires knowledge of Linux background processes and network connections.

Through the introduction of this article, I believe that readers have already understood the steps and precautions for using the command line to install MySQL on a Linux system. This installation method can be more flexible and efficient in certain environments.

The above is the detailed content of How to install mysql for linux command. 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