MySQL8.0をコンパイルしてインストールします

1. インストールパッケージをダウンロードする

[root@localhost src]# pwd
/usr/src
[root@localhost src]# ls
debug  kernels  mysql-8.0.20-el7-x86_64.tar.gz
[root@localhost src]# 

2. ユーザーを作成する

[root@localhost src]# groupadd -r mysql
[root@localhost src]# useradd -M -s /sbin/nologin -g mysql mysql

3. インストールパッケージを解凍し、データディレクトリを作成し、認証します。

//解压
[root@localhost src]# tar xf mysql-8.0.20-el7-x86_64.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-8.0.20-el7-x86_64  sbin  share  src
//创建软链接
[root@localhost local]# ln -sv mysql-8.0.20-el7-x86_64/ mysql
‘mysql’ -> ‘mysql-8.0.20-el7-x86_64/’
[root@localhost local]# chown -R mysql.mysql mysql*

//创建环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh 
[root@localhost local]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

//创建数据、日志目录,授权
[root@localhost local]# mkdir /opt/data
[root@localhost local]# mkdir /opt/error_log/
[root@localhost local]# mkdir /opt/slow_log
[root@localhost local]# touch /opt/error_log/mysql.log
[root@localhost local]# chown -R mysql.mysql /opt/data/
[root@localhost local]# chown -R mysql.mysql /opt/error_log/
[root@localhost local]# chown -R mysql.mysql /opt/error_log/mysql.log
[root@localhost local]# chown -R mysql.mysql /opt/slow_log/

4. データベースの初期化

[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/opt/data --lower-case-table-names=1
2023-04-24T06:46:34.319067Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-04-24T06:46:34.319155Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.20-el7-x86_64/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 1741
2023-04-24T06:46:34.336241Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-04-24T06:46:35.137438Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-04-24T06:46:36.121012Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ht1uVqbMX4/t

注意密码在最后  ht1uVqbMX4/t

5. 設定ファイルの生成

//清空原有的配置文件,追加以下内容
[root@localhost local]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/opt/data
socket=/usr/local/mysql/mysql.sock	
pid-file=/usr/local/mysql/mysql.pid
port=3306
lower_case_table_names=1
log_bin_trust_function_creators=1
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect = 'SET NAMES utf8mb4'
max_connect_errors=1000
max_connections=1510
skip_ssl #会禁用sll,导致客户端报错:Public Key Retrieval is not allowed

skip-name-resolve #可以禁用dns解析,但是,这样不能在mysql的授权表中使用主机名了,只能使用IP。
default-time-zone = '+08:00'
 
log-error=/opt/error_log/mysql.log
 
long_query_time=3
slow_query_log=on
slow_query_log_file=/opt/slow_log/slow.log
 
[client]
default-character-set = utf8mb4
socket=/usr/local/mysql/mysql.sock
 
[mysql]
default-character-set = utf8mb4
[root@localhost local]# 
//修改配置文件
[root@localhost mysql]# vim /usr/local/mysql/support-files/mysql.server 
46 basedir=/usr/local/mysql
47 datadir=/opt/data

6. MySQL を起動し、デフォルトのパスワードを変更します。

[root@localhost mysql]# /usr/local/mysql/support-files/mysql.server start

//查看端口3306
[root@localhost local]# ss -antl
State       Recv-Q Send-Q        Local Address:Port                       Peer Address:Port              
LISTEN      0      128                       *:111                                   *:*                  
LISTEN      0      128                       *:22                                    *:*                  
LISTEN      0      100               127.0.0.1:25                                    *:*                  
LISTEN      0      128                    [::]:111                                [::]:*                  
LISTEN      0      128                    [::]:22                                 [::]:*                  
LISTEN      0      100                   [::1]:25                                 [::]:*                  
LISTEN      0      70                     [::]:33060                              [::]:*                  
LISTEN      0      128                    [::]:3306                               [::]:*                  
[root@localhost local]# 

//修改密码,默认密码在初始化的时候已经生成
[root@localhost local]# mysql -uroot -p
Enter password: ht1uVqbMX4/t
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.20

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1';
Query OK, 0 rows affected (0.00 sec)

おすすめ

転載: blog.csdn.net/qq_49530779/article/details/130290275