CentOS6.9 MySQL 소스 설치
ETCMySQL
01. 의존성 파일 설치
# yum -y install ncurses-devel zlib curl libtermcap-devel lib-client-devel bzip2-devel cmake bison perl perl-devel
Complete!
5.5버전부터는 configure 명령어가 아닌 cmake 명령어를 이용하여 configure를 진행한다.
02. 리눅스 계정 생성
# groupadd mysql
# useradd -g mysql -M mysql -u 27
- groupadd : 시스템에 그룹 생성
- useradd : 사용자 생성. -g 소속될 그룹 지정. -M 옵션은 폴더 생성 안함.
03. 다운로드 및 압축 해제
# cd /usr/local/src
src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.59.tar.gz
src]# tar xzf mysql-5.5.59.tar.gz
2018-03-27 21:51:51 (11.1 MB/s) - “Mysql-5.5.59.tar.gz” saved [21050313/21050313]
04. 설치
src]# cd mysql-5.5.59
mysql-5.5.59]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data
mysql-5.5.59]# make && make install
--Build files have been written to: /usr/local/src/mysql-5.5.59 // cmake
[100%] Built target my_safe_process // make
-- Installing: /usr/local/mysql/man/man8/mysqld.8 // make install
- -DCMAKE_INSTALL_PREFIX : MySQL 설치 경로
- -DMYSQL_DATADIR : data 폴더 설치 경로
05. 환경설정 기본 파일 복사 및 수정
mysql-5.5.59]# cd /usr/local/mysql/support-files
support-files]# cp my-huge.cnf /etc/my.cnf // 설정 파일 복사
cp: overwrite ‘etc/my.cnf’? y // 덮어쓰기
- MySQL 둘 이상 or MariaDB 같이 사용할 경우
탐색 순위에 따라 /etc 에서 먼저 탐색한 후 해당 서버의 디렉토리를 탐색하므로
/etc/my.cnf를 삭제하고, 각 디렉토리 안에 my.cnf를 복사한다.
# rm /etc/my.cnf
support-files]# cp my-huge.cnf /usr/local/mysql/my.cnf
# vi /usr/local/mysql/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql/data
- 복사할 my-*.cnf 파일은 MySql 메모리에 따라 결정된다.
my-huge.cnf : 1-2GB일 경우
my-large.cnf : 512MB 이상일 경우
my-medium.cnf : 32-64MB 사이일 경우
my-small.cnf : 64MB 이하일 경우
06. 서비스 스크립트 및 서비스 등록
support-files]# cp mysql.server /etc/rc.d/init.d/mysqld // 구동 파일(실행 데몬) 복사
support-files]# vi /etc/rc.d/init.d/mysqld
(...)
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
(...)
07. MySql 초기화
mysql_install_db 스크립트는 서버 데이터 디렉토리를 생성한다.
모든 데이터 베이스의 권한, MySQL을 테스트할 때 사용하는 test 데이터 베이스를 갖고 있는 MySQL 데이터 베이스를 위한 디렉토리.
support-files]# cd /usr/local/mysql
mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mysql/data
Installing MySQL system tables...
180331 5:19:51 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
180331 5:19:51 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
180331 5:19:51 [Note] ./bin/mysqld (mysqld 5.5.59-log) starting as process 15034 ...
OK
Filling help tables...
180331 5:19:51 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
180331 5:19:51 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
180331 5:19:51 [Note] ./bin/mysqld (mysqld 5.5.59-log) starting as process 15041 ...
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 MySQL root USER !
To do so, start the server, then issue the following commands:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h dico password 'new-password'
Alternatively you can run:
./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 manual for more instructions.
You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
08. 권한 조정
# chown -R mysql:mysql /usr/local/mysql // mysql 폴더에 mysql 사용자를 소유자로 지정
# ll /usr/local | grep mysql // mysql의 권한 폴더 확인
drwxr-xr-x. 13 mysql mysql 4096 Mar 27 22:07 mysql
# chmod 755 /etc/rc.d/init.d/mysqld
- chown : 파일 또는 폴더의 소유자를 변경한다.
- chmod : 파일 또는 폴더의 사용 권한을 변경한다.
소유자 / 그룹 / anonymous == rwx rwx rwx (r:4 읽기, w:2 쓰기, x:1 실행)
ex) 775 = rwxrwxr-x : 소유자와 그룹은 모든 권한을 가지며, 그 외는 읽기와 실행 권한을 갖는다.
09. 구동 시작 (서비스 이용)
# service mysqld start
Starting MySQL.. SUCCESS!
- 종료
# service mysqld stop
Shutting down MySQL. SUCCESS!
10. MySQL 기본 보안 적용
반드시 MySQL 홈디렉토리(/usr/local/mysql)에서 실행할 것.
mysql]# ./bin/mysql_secure_installation // MySql 기본 보안 명령어.
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): [enter] // 초기 설치면 Enter
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y // MySql root 비밀번호 설정
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y // 익명 사용자 삭제
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y // MySQL 원격 접속 제한
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y // test DB 삭제
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y // 다시 시작(변경 적용)
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
11. 부팅 시 자동 실행하기 설정
# chkconfig --add mysqld
12. 주요 기능 PATH 등록
# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
# ln -s /usr/local/mysql/bin/mysqldump /usr/sbin/mysqldump
# ln -s /usr/local/mysql/bin/mysql_config /usr/sbin/mysql_config
# ln -s /usr/local/mysql/bin/mysqladmin /usr/sbin/mysqladmin
# ln -s /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
#. 환경변수 설정
기본 환경 변수에 설정. (mysql -u root -p 했을 때 mysql 못 찾을 경우)
# vi /root/.bash_profile
(...)
PATH=$PATH$HOME/bin:/usr/local/mysql/bin:
# source /root/.bash_profile
13. 접속
# mysql -u root -p비밀번호
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.5.59-log Source distribution
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>
14. 데이터베이스 및 테이블 생성
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+-----------------------+
| Database |
+-----------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+-----------------------+
4 rows in set (0.0 sec)
mysql> use test;
Database changed
mysql> create table test (no int, name varchar(20));
Query OK, 0 rows affected (0.10 sec)
mysql> show tables;
+-----------------------+
| Tables_in_test |
+-----------------------+
| test |
+-----------------------+
1 rows in set (0.0 sec)
mysql> insert into test (no, name) values (1, ‘test’);
Query OK, 1 row affected (0.04 sec)
mysql> select * from test;
+----------+----------+
| no | name |
+----------+----------+
| 1 | test |
+----------+----------+
1 rows in set (0.0 sec)
mysql> \q
Bye
# 비밀번호 재설정
# cd /usr/local/mysql/bin/
bin]# ./mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:
#. MySQL 메모리 튜닝
# vi /etc/my.cnf
(...)
innodb_buffer_pool_size = 16M
innodb_log_buffer_size = 8M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_lock_wait_timeout = 50
explicit_defaults_for_timestamp = TRUE
- innodb_buffer_pool_size : 임시 기억 공간 크기. 레코드나 인덱스의 캐쉬 등에 사용한다.
- innodb_additional_mem_pool_size : 레코드나 인덱스의 캐쉬등에 사용한다.
#. 서비스 없이 start, stop
# cd /usr/local/mysql/support-files
# mysql.server start
# mysql.server stop