Home > Database > Mysql Tutorial > body text

What is the method to install MySQL8.0.32 on Centos7.9

PHPz
Release: 2023-05-30 13:46:22
forward
1514 people have browsed it

Step one, download the compressed package

Download the community version of MySQL and download the corresponding version according to your needs, including the minimum installation version.

What is the method to install MySQL8.0.32 on Centos7.9

The second step is to decompress the compressed package and copy it to the installation directory.

Go to the folder where the compressed package is located and decompress it twice. Extract the xz file once and the tar file a second time.

xz -dv mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar
Copy after login

Copy the decompressed file to the directory where you want to install it. I want to install MySQL to /usr/local/mysql, so run the following command and copy the decompressed file there

sudo cp -r mysql-8.0.32-linux-glibc2.12-x86_64/* /usr/local/mysql
Copy after login

Here we need to modify the permissions of the following installation directory. Since we use the mysql user to run the database, we need to change the owner of the installation directory to mysql. If the system does not have it, we need to add the mysql user and group. We only use mysql to run the program. Therefore, mysql is specified to prohibit login and increase security

sudo groupadd mysql
sudo useradd mysql -s /usr/sbin/nologin -g mysql
Copy after login

Modify the owner of the installation directory to mysql

chown -R mysql:mysql /usr/local/mysql/
Copy after login

The third step is to edit the configuration file

Edit the configuration file, we Place the configuration file in /etc/my.cnf

The configuration is as follows:

[client]
port=3306
# 端口
# mysqlx_port=33060
socket=/var/lib/mysql/mysql.sock
# mysqlx_socket=/var/lib/mysqlx.sock

[mysqld]
# skip-grant-tables
# mysql安装目录
basedir=/usr/local/mysql/
# mysql数据库目录
datadir=/var/lib/mysql/data/
port=3306
innodb_file_per_table=1
character-set-server=UTF8MB4
mysqlx_port=33060
socket = /var/lib/mysql/mysql.sock
# mysqlx_socket=/var/lib/mysql/mysqlx.sock

[mysqld_safe]
# 错误日志
log-error=/var/log/mysql/error.log
# pid文件
pid-file=/usr/local/mysql/mysqld.pid
tmpdir=/var/lib/mysql/mysql
Copy after login

The fourth step is to determine some related directories

Edit the file support-files/mysql. server, modify the relevant directories inside

Installation directory basedir=/usr/local/mysql

Configuration directory/etc/my.cnf

Database file directory datadir=/var /lib/mysql/data/

pid file pid-file=/usr/local/mysql/mysqld.pid

The fifth step, initialize the database

Initialize the database, Note that after successful initialization, the terminal will display the root account password, which must be saved

sudo ./bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize
Copy after login

Step 6. Start the database, connect and change the root password

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

Connect to the database, change the root password

ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
Copy after login

The sixth step, protect the MySQL process

Create a daemon program to ensure that it can start automatically after the server is restarted. Run

sudo vim /etc/systemd/system/mysql.service
Copy after login

The content is as follows, where User and Group are mysql

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
#Restart=on-failure
#RestartPreventExitStatus=1
#PrivateTmp=false
Copy after login
# 使能
sudo systemctl enable mysql.service
# 启动
sudo systemctl start mysql.service
# 查看状态
sudo systemctl status mysql.service
Copy after login

Step 7, Verification

Restart the server to verify whether the mysql process is started

The above is the detailed content of What is the method to install MySQL8.0.32 on Centos7.9. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
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