Ubuntu 18.04 : MariaDB 10.3.12 컴파일, 설치

Database 2019.01.22 15:53 Posted by 파란크리스마스

출처

리눅스 정보 조회

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

$ cat /etc/*-release | uniq
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
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"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

리눅스 비트 확인

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

$ getconf LONG_BIT
64

관련패키지 설치

$ sudo apt-get update
$ sudo apt-get 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-get install cmake

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

$ wget https://downloads.mariadb.org/interstitial/mariadb-10.3.12/source/mariadb-10.3.12.tar.gz
$ tar xvf mariadb-10.3.12.tar.gz
$ cd mariadb-10.3.12/
$ sudo cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mariadb103 \
-DMYSQL_DATADIR=/usr/local/mariadb103/data \
-DMYSQL_UNIX_ADDR=/usr/local/mariadb103/mysql.sock \
-DSYSCONFDIR=/usr/local/mariadb103 \
-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
$ sudo make
$ sudo make install

환경설정

$ sudo vi /usr/local/mariadb103/my.cnf

[mysqld]
# port=3306
# basedir=/usr/local/mysql57
# datadir=/usr/local/mysql57/data
# pid-file=/usr/local/mysql57/mysqld.pid
# log_error=/usr/local/mysql57/mysql_error.log
# lc-messages-dir=/usr/local/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

[mysql]
default-character-set=utf8

[client]
default-character-set=utf8

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

$ sudo chown -R mysql:mysql /usr/local/mariadb103

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

$ cd /usr/local/mariadb103
$ scripts/mysql_install_db --no-defaults --user=mysql --datadir=/usr/local/mariadb103/data --basedir=/usr/local/mariadb103 -v
Installing MariaDB/MySQL system tables in '/usr/local/mariadb103/data' ...
OK
 
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
 
 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
 
'/usr/local/mariadb103/bin/mysqladmin' -u root password 'new-password'
'/usr/local/mariadb103/bin/mysqladmin' -u root -h bluesanta-desktop password 'new-password'
 
Alternatively you can run:
'/usr/local/mariadb103/bin/mysql_secure_installation'
 
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
 
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
 
You can start the MariaDB daemon with:
cd '/usr/local/mariadb103' ; /usr/local/mariadb103/bin/mysqld_safe --datadir='/usr/local/mariadb103/data'
 
You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mariadb103/mysql-test' ; perl mysql-test-run.pl
 
Please report any problems at http://mariadb.org/jira
 
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

root 암호 초기화

$ bin/mysqld_safe --skip-grant-tables &
[1] 11396
mysql@bluesanta-desktop:/usr/local/mariadb103$ 190122 23:11:49 mysqld_safe Logging to '/usr/local/mariadb103/data/bluesanta-desktop.err'.
190122 23:11:49 mysqld_safe Starting mysqld daemon with databases from /usr/local/mariadb103/data

mysql@bluesanta-desktop:/usr/local/mariadb103$ bin/mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.12-MariaDB-log Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> 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
MariaDB [mysql]> update user set authentication_string = password('sqldba') where user = 'root';
Query OK, 4 rows affected (0.001 sec)
Rows matched: 4  Changed: 4  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [mysql]> quit
Bye

mariadb 서비스 등록

서비스 mariadb 파일 복사

$ sudo cp /usr/local/mariadb103/support-files/mysql.server /etc/init.d/mariadb

mariadb 수정

$ sudo vi /etc/init.d/mariadb

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

basedir=/usr/local/mariadb103
datadir=/usr/local/mariadb103/data

  # Try to find basedir in /etc/my.cnf
  conf=/usr/local/mariadb103/my.cnf

mariadb 서비스 등록

$ sudo update-rc.d mariadb defaults

mariadb 서비스 실행

$ sudo systemctl start mariadb.service
$ sudo systemctl status mariadb.service
● mariadb.service - LSB: start and stop MariaDB
   Loaded: loaded (/etc/init.d/mariadb; generated)
   Active: active (running) since Tue 2019-01-22 22:59:51 KST; 11s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 10984 ExecStart=/etc/init.d/mariadb start (code=exited, status=0/SUCCESS)
    Tasks: 32 (limit: 4915)
   CGroup: /system.slice/mariadb.service
           ├─11058 /bin/sh /usr/local/mariadb103/bin/mysqld_safe --datadir=/usr/local/mariadb103/data --pid-file=/us
           └─11191 /usr/local/mariadb103/bin/mysqld --basedir=/usr/local/mariadb103 --datadir=/usr/local/mariadb103/
 
 1월 22 22:59:50 bluesanta-desktop systemd[1]: Starting LSB: start and stop MariaDB...
 1월 22 22:59:50 bluesanta-desktop mariadb[10984]: Starting MariaDB
 1월 22 22:59:50 bluesanta-desktop mariadb[10984]: .190122 22:59:50 mysqld_safe Logging to '/usr/local/mariadb103/da
 1월 22 22:59:50 bluesanta-desktop mariadb[10984]: 190122 22:59:50 mysqld_safe Starting mysqld daemon with databases
 1월 22 22:59:51 bluesanta-desktop mariadb[10984]:  *
 1월 22 22:59:51 bluesanta-desktop systemd[1]: Started LSB: start and stop MariaDB.

mariadb 서비스 종료

$ sudo systemctl stop mariadb.service

사용자 추가

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

DB 종속적 사용자 추가

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