OS/Linux

Ubuntu 20.04 : MySQL 5.7.44 컴파일(수동설치)

파란크리스마스 2023. 12. 22. 23:20
728x90

출처

리눅스 정보 조회

출처 : 리눅스 종류 확인, 리눅스 버전 확인 - 제타위키

$ cat /etc/*-release | uniq
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS"
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

리눅스 비트 확인

출처 : 리눅스 32비트 64비트 확인 - 제타위키

$ getconf LONG_BIT
64

관련패키지 설치

$ sudo apt install gcc g++ libncurses5-dev libxml2-dev openssl libssl-dev curl libcurl4-openssl-dev libjpeg-dev libpng-dev libfreetype6-dev libsasl2-dev autoconf libncurses5-dev

MySQL 계정 만들기

$ sudo groupadd mysql
$ sudo useradd -g mysql -s /bin/bash -m mysql

cmake 설치

$ sudo apt install cmake pkg-config

MySQL 소스 다운로드, 압축해제, 컴파일, 설치

$ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.44.tar.gz 
$ tar xvf mysql-boost-5.7.44.tar.gz 
$ cd mysql-5.7.44
$ cmake \
-DCMAKE_INSTALL_PREFIX=/Server/MySQL/mysql57 \
-DMYSQL_DATADIR=/Server/MySQL/mysql57/data \
-DMYSQL_UNIX_ADDR=/Server/MySQL/mysql57/mysql.sock \
-DSYSCONFDIR=/Server/MySQL/mysql57 \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_USER=mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DDOWNLOAD_BOOST=0 -DWITH_BOOST=./boost
$ make 
$ make install

환경설정

$ vi /Server/MySQL/mysql57/my.cnf

my.cnf

[mysqld]
port=3306
event_scheduler = ON
basedir=/Server/MySQL/mysql57
datadir=/Server/MySQL/mysql57/data
# pid-file=/Server/MySQL/mysql57/mysqld.pid
# log_error=/Server/MySQL/mysql57/mysql_error.log
# lc-messages-dir=/Server/MySQL/mysql57/share

init_connect=SET collation_connection = utf8_general_ci
init_connect=SET NAMES utf8
character-set-server=utf8
collation-server=utf8_general_ci
# table_cache=1024
max_connections=2048
max_user_connections=500
max_connect_errors=10000
wait_timeout=300
query_cache_type = 1
query_cache_size = 128M
query_cache_limit = 5M
slow_query_log
long_query_time=3
max_allowed_packet=16M
sort_buffer_size = 2M
# skip-innodb
skip-name-resolve
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names = 1

[mysql]
default-character-set=utf8

[client]
default-character-set=utf8

MySQL 설치 디렉토리 mysql 계정으로 권한 수정

$ sudo chown -R mysql:mysql /Server/MySQL/mysql57

MySQL 데이터베이스 초기화 (mysql 계정으로 실행)

$ su mysql
mysql@bluexmas:~$ cd /Server/MySQL/mysql57
mysql@bluexmas:/Server/MySQL/mysql57$ bin/mysql_install_db --no-defaults --user=mysql --datadir=/Server/MySQL/mysql57/data --basedir=/Server/MySQL/mysql57 -v
2023-12-23 19:54:33 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2023-12-23 19:54:33 [NOTE]    Creating data directory /Server/MySQL/mysql57/data
2023-12-23 19:54:33 [NOTE]    Generating random password to /home/mysql/.mysql_secret...done.
2023-12-23 19:54:33 [NOTE]    Executing /Server/MySQL/mysql57/bin/mysqld --no-defaults --bootstrap --datadir=/Server/MySQL/mysql57/data --lc-messages-dir=/Server/MySQL/mysql57/share --lc-messages=en_US --basedir=/Server/MySQL/mysql57
2023-12-23 19:54:37 [NOTE]    Creating system tables...done.
2023-12-23 19:54:37 [NOTE]    Filling system tables with data...done.
2023-12-23 19:54:37 [NOTE]    Filling help table with data...done.
2023-12-23 19:54:37 [NOTE]    Creating user for internal session service...done.
2023-12-23 19:54:37 [NOTE]    Creating default user root@localhost
2023-12-23 19:54:37 [NOTE]    Creating default proxy root@localhost
2023-12-23 19:54:37 [NOTE]    Creating sys schema
2023-12-23 19:54:38 [NOTE]    done.
2023-12-23 19:54:39 [WARNING] The bootstrap log isn't empty:
2023-12-23 19:54:39 [WARNING] 2023-12-23T10:54:33.906900Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

MySQL 서비스 등록

서비스 mysqld 파일 복사

$ sudo cp /Server/MySQL/mysql57/support-files/mysql.server /etc/init.d/mysqld57

mysqld 수정

$ sudo vi /etc/init.d/mysqld57

mysqld파일을 열어서 basedir에 mysql이 설치된 디렉토리와 데이터 디렉토리(datadir)를 설정한다.

basedir=/Server/MySQL/mysql57
datadir=/Server/MySQL/mysql57/data

mysqld 서비스 등록

$ sudo update-rc.d mysqld57 defaults

mysqld 서비스 실행

$ sudo service mysqld57 start
$ sudo service mysqld57 status
● mysqld57.service - LSB: start and stop MySQL
     Loaded: loaded (/etc/init.d/mysqld57; generated)
     Active: active (running) since Sat 2023-12-23 19:57:54 KST; 15s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 61861 ExecStart=/etc/init.d/mysqld57 start (code=exited, status=0/SUCCESS)
      Tasks: 29 (limit: 18671)
     Memory: 175.0M
        CPU: 772ms
     CGroup: /system.slice/mysqld57.service
             ├─61881 /bin/sh /Server/MySQL/mysql57/bin/mysqld_safe --datadir=/Server/MySQL/mysql57/data --pid-file=/Ser>
             └─62295 /Server/MySQL/mysql57/bin/mysqld --basedir=/Server/MySQL/mysql57 --datadir=/Server/MySQL/mysql57/d>
 
12월 23 19:57:53 bluesanta-desktop systemd[1]: Starting LSB: start and stop MySQL...
12월 23 19:57:53 bluesanta-desktop mysqld57[61861]: Starting MySQL
12월 23 19:57:53 bluesanta-desktop mysqld57[61861]: .
12월 23 19:57:53 bluesanta-desktop mysqld57[61881]: Logging to '/Server/MySQL/mysql57/data/bluesanta-desktop.err'.
12월 23 19:57:54 bluesanta-desktop mysqld57[61861]:  *
12월 23 19:57:54 bluesanta-desktop systemd[1]: Started LSB: start and stop MySQL.

root 암호 초기화

권한을 무시하고 mysql 서버 실행

mysql@bluexmas:/Server/MySQL/mysql57$ bin/mysqld_safe --skip-grant-tables &
[1] 62790
mysql@bluesanta-desktop:/Server/MySQL/mysql57$ 2023-12-23T11:06:36.242790Z mysqld_safe Logging to '/Server/MySQL/mysql57/data/bluesanta-desktop.err'.
2023-12-23T11:06:36.272476Z mysqld_safe Starting mysqld daemon with databases from /Server/MySQL/mysql57/data

root 암호 설정

mysql@bluexmas:/Server/MySQL/mysql57$ 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.44-log Source distribution
 
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
 
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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> update user set authentication_string = password('sqldba') where user = 'root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> quit
Bye

ERROR 1820 (HY000) 오류 해결

mysql@bluexmas:/Server/MySQL/mysql57$ bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.44-log
 
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
 
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> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> SET PASSWORD = PASSWORD('sqldba');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> 

사용자 추가

mysql> create user 'user1'@'%' identified by 'userpw'; 
mysql> grant all privileges on *.* to 'user1'@'%' with grant option; 
mysql> flush privileges;

사용자 추가

mysql> create user 'terecal'@'%' identified by '****';
mysql> GRANT ALL privileges ON terecal_db.* TO 'terecal'@'%';
mysql> flush privileges;