10 분 안에 MySQL (Linux 버전)을 다운로드하고 설치하는 방법을 알아 봅니다.

MySQL 다운로드

다운로드하고 다운로드하려는 MySQL 버전을 선택하십시오.

공식 웹 사이트 다운로드 주소 :
https://downloads.mysql.com/archives/community/

아래에서는 5.7.24를 예로 들어
여기에 사진 설명 삽입
매개 변수 설명 을 다운로드하고 설치합니다 .

제품 버전 : 제품 버전, 즉 MySQL 버전

운영 체제 : 운영 체제, Linux 시스템은 Linux Generic (Linux 일반)을 선택할 수 있습니다.

OS 버전 : 시스템 버전, x86, 64 비트는 64 비트, x86, 32 비트는 32 비트

다음은 mysql5.7.24의 다운로드 연결입니다.

https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

설치 패키지의 경우 위와 같이 링크 주소를 복사하여 Linux에서 다운로드하거나 Windows에서 다운로드하여 Linux 서버에 업로드 할 수 있습니다.

MySQL 설치

설치 패키지 다운로드
// wget 명령을 직접 사용하여 Linux 서버에 다운로드합니다.

wget  https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

// 압축 된 패키지의 압축을 풉니 다. mysql-5.7.24.tar.gz는 제가 이름을 바꾼 압축 패키지이고, 원래 파일 이름은 mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz입니다.

tar -zxvf mysql-5.7.24.tar.gz 

압축 해제가 완료되면 다음과 같은 mysql-5.7.24-linux-glibc2.12-x86_64 폴더가 생성됩니다.

[root@localhost data]# ll
总用量 629816
drwxr-xr-x. 9 root root       129 12月  8 17:19 mysql-5.7.24-linux-glibc2.12-x86_64
-rw-r--r--. 1 root root 644930593 10月  4 2018 mysql-5.7.24.tar.gz

// 폴더 이름 바꾸기

mv mysql-5.7.24-linux-glibc2.12-x86_64/ mysql-5.7.24`

// mysql 그룹을 만들고 mysql 그룹에 가입 할 mysql 사용자를 만듭니다.

# groupadd mysql
# useradd -g mysql mysql
passwd mysql #设置密码

참고 : groupadd는 그룹을 추가하는 것이고, useradd -g는 특정 그룹에 사용자를 추가하고, 위의 useradd -g mysql mysql, 첫 번째 mysql은 그룹의 이름을, 두 번째는 사용자의 이름을 나타냅니다.

// mysql 디렉토리가 속한 그룹 및 사용자 변경

# chown -R mysql:mysql mysql-5.7.24/

설명 : 첫 번째 mysql은 소유자를 나타내고 두 번째 mysql은 그룹을 나타냅니다.

// mysql 데이터를 저장할 디렉터리 생성

# mkdir /usr/mysql

// mysql 구성 파일을 수정합니다. mysql 구성 파일의 기본 위치는 /etc/my.cnf입니다. 먼저 원래 구성 파일을 삭제 한 다음 새 구성 파일 (my.cnf)을 만듭니다.

다음은 원래 구성 파일 내용입니다.

# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

먼저 원래 구성 파일을 삭제하십시오.

# rm -rf /etc/my.cnf

새 프로필 만들기

[root@localhost etc]# vi my.cnf

내용은 다음과 같습니다

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306 
# 设置mysql的安装目录
basedir=/root/data/mysql-5.7.24
# 设置mysql数据库的数据的存放目录
datadir= /usr/mysql
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB 
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true

// mysql을 초기화하고 먼저 mysql 디렉토리로 이동합니다.

# cd /root/data/mysql-5.7.24

# 구성 초기화를 위해 5.7.24의 초기화 명령은 mysql_install_db 대신 mysqld --initialize를 사용합니다.

bin/mysqld --initialize  --user=mysql --basedir=/root/data/mysql-5.7.24/ --datadir=/usr/mysql

명령을 실행하면 반환 된 결과에 임시 암호 (다음과 같이)가 생성되며, 다음 암호는 6kDG / * QwSXcd입니다.

[Note] A temporary password is generated for root@localhost: 6kDG/*QwSXcd

// mysql을 시작하고 mysql을 시작합니다. bin 디렉토리에서 mysqld_safe 스크립트를 사용하고 먼저 mysql의 bin 디렉토리로 이동합니다.

# cd /root/data/mysql-5.7.24/bin/

mysqld_safe 스크립트를 사용하여 Mysql 시작

./mysqld_safe --user=mysql &

예 :

[root@localhost bin]# ./mysqld_safe --user=mysql &
[1] 2875
[root@localhost bin]# 
[root@localhost bin]# Logging to '/usr/mysql/localhost.localdomain.err'.
2020-12-09T09:42:11.647387Z mysqld_safe Starting mysqld daemon with databases from /usr/mysql

// 시작 후 초기 계정 (루트)과 이전에 생성 된 임시 비밀번호를 사용하여 mysql에 로그인하고 mysql -uroot -p를 사용하여 콘솔로 들어갑니다.

# 다음 명령어를 입력하고 비밀번호를 입력하세요. 생성 한 임시 비밀번호는 6kDG / * QwSXcd입니다.

  ./mysql -u root -p

예 :

[root@localhost bin]# ./mysql -u root -p  
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24

Copyright (c) 2000, 2018, 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 명령 줄 모드, 즉 mysql>로 들어가고 아래 비밀번호를 수정합니다.

비밀번호 수정 : set password = password ( 'your password');

문장의 끝을 의미하는;로 끝납니다.

예 :

mysql> set password=password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)

루트 계정의 호스트 주소를 설정하고 원격으로 연결하도록 수정합니다.

grant all privileges on *.* to 'root'@'%' identified by 'root';

참고 : 위의 루트 계정 암호를 루트로 변경했기 때문에 위의 첫 번째 루트는 루트 계정을 나타내고 두 번째 루트는 루트 계정의 암호입니다.

예 :

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql 명령을 실행 한 후 mysql 명령 모드를 종료 할 수 있습니다. mysql 모드를 종료하려면 quit를 입력하십시오.

추천

출처blog.csdn.net/qq_36551991/article/details/111084197