Mysql shell script 1

RDB/mysql 2019. 9. 9. 11:04
반응형

 

1.mysql 쉘 스크립트(접속)

 

보통은 mysql -uroot -p 로 DB 루트 로그인을 하는데 보안에 안전한 내부망 테스트 장비나 원격지원등 사유로 인해 스크립트로 만들어 쓸 때도 있다.

postgres 쓸때는 따로 라이브러리가 있었던 거 같은데 mysql은 자체라이브러리가 있어서 편하다.

 

 

[test@~]$ vi mysql_conn.sh

--------------------------------------------------------------------------------------
#!/bin/sh
/usr/local/mysql/bin/mysqladmin -uroot -p(패스워드) --socket=/tmp/mysql.sock

:wq

 

[test@~]$ ./mysql_conn.sh
Commands end with ; or \g.
Your MySQL connection id is 94
Server version: 5.7.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

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

MySQL [(none)]> show processlist;
+----+------+-----------+------+---------+------+----------+------------------+
| Id | User | Host      | db   | Command | Time | State    | Info             |
+----+------+-----------+------+---------+------+----------+------------------+
| 94 | root | localhost | NULL | Query   |    0 | starting | show processlist |
+----+------+-----------+------+---------+------+----------+------------------+
1 row in set (0.02 sec)

MySQL [(none)]>

 

간단하다 

 

끝.

 

 

반응형

'RDB > mysql' 카테고리의 다른 글

mysql varchar 한글 입력사이즈 계산 어떻게 하는 거야?  (0) 2019.11.15
mysql shell script 2  (0) 2019.09.09
Xtrabackup 2.49 설치  (0) 2019.09.06
varchar 255가 넘는 인덱스 추가  (0) 2019.09.05
mysql 5.7 binary 설치 3  (0) 2019.08.30
블로그 이미지

dung beetle

취미는 데이터 수집 직업은 MYSQL과 함께 일하는 DBA의 소소한 일상 이야기

,

Xtrabackup 2.49 설치

RDB/mysql 2019. 9. 6. 16:30
반응형

DBA의 역할중 가장 중요한 건 Data 백업과 튜닝, 점검시 downtime 최소화..등등..

DB의 데이터가 쌓여..100G가 이상 되면 슬슬 mysqldump로는 한계를 만나게 된다.

이때 다른 백업을 찾게 되는데..

여러 오픈소스중 성능이 우수한 Xtrabackup 을 설치하고 테스트한다.

 

환경 : OS CentOS 6.9

 

1) 설치파일 확인

-- xtrabacup 설치하기 위해 기본적인 RPM 이 설치되어있는지 확인하고 없으면 설치해야한다.

#su권한

[root@~]# rpm -qa | grep perl-DBD
perl-DBD-MySQL-4.013-3.el6.x86_64
[root@~]# rpm -qa | grep perl-Time
perl-Time-HiRes-1.9721-144.el6.x86_64
[[root@~]# rpm -qa | grep libev
libevent-1.4.13-4.el6.x86_64

-->libev 없다. 찾아서 설치한다.

 

 

2) xtrabackup 설치(rpm 설치)

#설치 파일은 2개

percona-xtrabackup-24-2.4.9-1.el6.x86_64.rpm

percona-xtrabackup-24-debuginfo-2.4.9-1.el6.x86_64.rpm

 

-->libev 없는거 먼저 설치

[root@~]# rpm -Uvh libev-4.03-3.el6.x86_64.rpm
경고: libev-4.03-3.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
준비 중...               ########################################### [100%]
   1:libev                  ########################################### [100%]
  
확인) rpm -qa | grep libev
libev-4.03-3.el6.x86_64

설치)
[root@~]# rpm -Uvh percona-xtrabackup-24-2.4.9-1.el6.x86_64.rpm
경고: percona-xtrabackup-24-2.4.9-1.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
준비 중...               ########################################### [100%]
   1:percona-xtrabackup-24  ########################################### [100%]   
[root@~]# rpm -Uvh percona-xtrabackup-24-debuginfo-2.4.9-1.el6.x86_64.rpm
경고: percona-xtrabackup-24-debuginfo-2.4.9-1.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
준비 중...               ########################################### [100%]
   1:percona-xtrabackup-24-d########################################### [100%] 

 

[root@~]#

설치 끝 ~~~!!

어디에 설치된거야?? RPM 설치의 단점..

실행파일은 여기에 있다.

/usr/bin/innobackupex

 

3) 백업

-- 쉘 스크립트로 만들어 Crontab 에 등록해서 편하게 쓴다.

쉘은 구글링~~!!

 ./xtrabackup.sh

 

vi xtrabackup.sh

----------------------------------------------------------------------------------

/usr/bin/innobackupex \
    --host=127.0.0.1 \
    --user=root \
    --password='DB패스워드' \
    --ibbackup=xtrabackup \
    --no-lock \
    --no-timestamp \
    ${BACKUP_LOCATED}/${NOW_DATE} \
    1> $PWD/logs/innobackupex_${NOW_DATE}.err 2> $PWD/logs/innobackupex_${NOW_DATE}.log

 -->스크립트 내 xtrabackup 옵션들 중에 가장 중요한 것은 실시간 CRUD가 일어나는 DB는 mysql 엔진을 innodb를 쓰기 때문에 핫백업을 하려면 ibbackupno-lock 옵션이 가장 중요하다.

 

4) 재생성

 

4-1) 현재 사용중인 DB 중단

service mysqld stop

 

4-2) 디스크 비우고 백업

mv mysqldb_data mysqldb_data_bak
mkdir mysqldb_data
chown -Rf mysql:mysql mysqldb_data

 

4-3) xtrabacup apply 로그 복구

[root@~]# innobackupex --defaults-file=/etc/my.cnf --datadir=/home/mysql/mysqldb_data --apply-log /backup/innobackup/20190906_06/

 

190906 16:04:06 innobackupex: Starting the apply-log operation

IMPORTANT: Please check that the apply-log run completes successfully.
           At the end of a successful apply-log run innobackupex
           prints "completed OK!".

innobackupex version 2.4.9 based on MySQL server 5.7.13 Linux (x86_64) (revision id: a467167cdd4)
xtrabackup: cd to /home/mysql/backup/innobackup/20190906_06/
xtrabackup: This target seems to be already prepared.
InnoDB: Number of pools: 1
xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup:   innodb_data_home_dir = .
xtrabackup:   innodb_data_file_path = ibdata1:500M;ibdata2:500M;ibdata3:10M:autoextend
xtrabackup:   innodb_log_group_home_dir = .
xtrabackup:   innodb_log_files_in_group = 4
xtrabackup:   innodb_log_file_size = 268435456
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup:   innodb_data_home_dir = .
xtrabackup:   innodb_data_file_path = ibdata1:500M;ibdata2:500M;ibdata3:10M:autoextend
xtrabackup:   innodb_log_group_home_dir = .
xtrabackup:   innodb_log_files_in_group = 4
xtrabackup:   innodb_log_file_size = 268435456
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Highest supported file format is Barracuda.
InnoDB: Removed temporary tablespace data file: "ibtmp1"
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: 5.7.13 started; log sequence number 2347797778603
InnoDB: xtrabackup: Last MySQL binlog file position 7587824, file name ./mysql-bin.000001

xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 2347797779605
InnoDB: Number of pools: 1
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup:   innodb_data_home_dir = .
xtrabackup:   innodb_data_file_path = ibdata1:500M;ibdata2:500M;ibdata3:10M:autoextend
xtrabackup:   innodb_log_group_home_dir = .
xtrabackup:   innodb_log_files_in_group = 4
xtrabackup:   innodb_log_file_size = 268435456
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Highest supported file format is Barracuda.
InnoDB: Removed temporary tablespace data file: "ibtmp1"
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: 5.7.13 started; log sequence number 2347797779605
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 2347797780598
190906 16:04:11 completed OK!

 

4-4) xtrabackup 데이터복구

 [root@~]# innobackupex --defaults-file=/etc/my.cnf --datadir=/home/mysql/mysqldb_data --copy-back /backup/innobackup/20190906_06/

...

190906 16:34:27 [01] Copying ./WWW/TB_COM_CD_DTL.frm to /home/mysql/mysqldb_data/WWW/TB_COM_CD_DTL.frm
190906 16:34:27 [01]        ...done
190906 16:34:27 [01] Copying ./WWW/TB_CM_WWW_CTGR_SORT.frm to /home/mysql/mysqldb_data/WWW/TB_CM_WWW_CTGR_SORT.frm
190906 16:34:27 [01]        ...done
190906 16:34:27 [01] Copying ./WWW/TB_COM_WWW_CTGR.frm to /home/mysql/mysqldb_data/WWW/TB_COM_WWW_CTGR.frm
190906 16:34:27 [01]        ...done
190906 16:34:27 [01] Copying ./WWW/TB_PM_WWW_010PAY_RESERVE.frm to /home/mysql/mysqldb_data/WWW/TB_PM_WWW_010PAY_RESERVE.frm
190906 16:34:27 [01]        ...done
190906 16:34:27 [01] Copying ./WWW/TB_SM_WWW_INFO.ibd to /home/mysql/mysqldb_data/WWW/TB_SM_WWW_INFO.ibd
190906 16:34:27 [01]        ...done
190906 16:34:27 [01] Copying ./WWW/TB_CM_WWW_CTGR_SORT.ibd to /home/mysql/mysqldb_data/WWW/TB_CM_WWW_CTGR_SORT.ibd
190906 16:34:27 [01]        ...done
190906 16:34:27 [01] Copying ./WWW/TB_PM_WWW_AUTOPAY.frm to /home/mysql/mysqldb_data/WWW/TB_PM_WWW_AUTOPAY.frm
190906 16:34:27 [01]        ...done
190906 16:34:27 [01] Copying ./WWW/TB_WWW_ACCT_RCVM_HIST.ibd to /home/mysql/mysqldb_data/WWW/TB_WWW_ACCT_RCVM_HIST.ibd
190906 16:34:27 [01]        ...done
190906 16:34:27 [01] Copying ./WWW/TB_WWW_ACCT_RCVM_DRW_HIST.frm to /home/mysql/mysqldb_data/WWW/TB_WWW_ACCT_RCVM_DRW_HIST.frm
190906 16:34:27 [01]        ...done
190906 16:34:27 completed OK!

 [root@~]#

 

 

4-5) DB 시작

[root@~]# service mysqld start
Starting MySQL.190906 17:35:42 mysqld_safe Logging to '/home/mysql/mariadb_logs/error/mysql.err'.
190906 17:35:42 mysqld_safe Starting mysqld daemon with databases from /home/mysql/mariadb_data
.                                                          [실패]

190906 17:35:43 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode'
190906 17:35:43 [ERROR] InnoDB: The system tablespace must be writable!
190906 17:35:43 [ERROR] Plugin 'InnoDB' init function returned error.
190906 17:35:43 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
190906 17:35:43 [Note] Plugin 'FEEDBACK' is disabled.
190906 17:35:43 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
190906 17:35:43 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
190906 17:35:43 [Note] Server socket created on IP: '::'.
190906 17:35:43 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
190906 17:35:43 mysqld_safe mysqld from pid file /home/mysql/mariadb_data/test.pid ended'

 

--> 권한 오류 확인

/mariadb_data 아래 파일이 root 권한으로 인해 발생한 문제로 권한을 mysql로 수정한다.
[root@~]# chown -Rf mysql:mysql mysqldb_data
[root@~]# chown -Rf mysql:mysql mariadb_logs

 

[mysql@~]# service mysqld start
Starting MySQL.190906 17:52:46 mysqld_safe Logging to '/home/mysql/mariadb_logs/error/mysql.err'.
190906 17:52:46 mysqld_safe Starting mysqld daemon with databases from /home/mysql/mariadb_data
..                                                         [  OK  ]

끝~~!!

 

 

 

 

 

반응형

'RDB > mysql' 카테고리의 다른 글

mysql shell script 2  (0) 2019.09.09
Mysql shell script 1  (0) 2019.09.09
varchar 255가 넘는 인덱스 추가  (0) 2019.09.05
mysql 5.7 binary 설치 3  (0) 2019.08.30
mysql 5.7 binary 설치 2  (0) 2019.08.28
블로그 이미지

dung beetle

취미는 데이터 수집 직업은 MYSQL과 함께 일하는 DBA의 소소한 일상 이야기

,
반응형

mysql 은 기본 defult character 셋을 utfmd4로 설정해놓았다.

다만 이모티콘등을 사용하지 않는데 굳이 utfmd4를 써서 자원을 낭비할 필요가 없다.

대부분의 테이블은 utf8 3Byte로 사용하고 있고

 

테이블 생성 character set = utf8 이다.

이렇게 설정할 경우 varchar 255 * 3 = 762 바이트(해더를 뺀 254 *3)가 넘는 데이터 컬럼은 인덱스 생성이 안된다.

 

mysql> ALTER TABLE entry ADD UNIQUE INDEX (name(255));
ERROR
1071 (42000): Specified key was too long; max key length is 762bytes

 

하지만 reg_id등 암호화된 데이터를 갖은 컬럼도 인덱스 생성이 필요할 경우가 있다.

이럴 가능하게 하려면 일단 mysql 의 시스템 환경변수를 확인해야 한다.

 

1) 지원가능여부확인 

 #mysq. 5.7
mysql> show variables like 'innodb_file_format';
+--------------------+-----------+
| Variable_name      | Value     |
+--------------------+-----------+
| innodb_file_format | Barracuda |
+--------------------+-----------+
1 row in set (0.00 sec)
mysql> show variables like 'innodb_file_per_table';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| innodb_file_per_table | ON    |
+-----------------------+-------+
1 row in set (0.00 sec)
mysql> show variables like 'innodb_large_prefix';
+---------------------+-------+
| Variable_name       | Value |
+---------------------+-------+
| innodb_large_prefix | ON    |
+---------------------+-------+
1 row in set (0.00 sec)



#보통 mysql 5.7은 defualt로 전부 가능하게 설정되어있다.
#가장 좋은 성능튜닝은 version up 이다.ㅎㅎ


# mysql 5.5를 확인해본다.
mysql> show variables like 'innodb_file_format';
+--------------------+----------+
| Variable_name      | Value    |
+--------------------+----------+
| innodb_file_format | Antelope |
+--------------------+----------+
1 row in set (0.00 sec)
mysql> show variables like 'innodb_file_per_table';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| innodb_file_per_table | OFF   |
+-----------------------+-------+
1 row in set (0.00 sec)
mysql> show variables like 'innodb_large_prefix';
+---------------------+-------+
| Variable_name       | Value |
+---------------------+-------+
| innodb_large_prefix | OFF   |
+---------------------+-------+
1 row in set (0.00 sec)



#불가능하다. 지원하지 않는다.
#mysql 5.7 버전부터 지원하며 5.6의경우 특정 버전 이상부터 지원하는 것으로 알고 있다.

 

2) 인덱스 생성

1) 임시테이블생성(바라쿠다엔진선택)
아래처럼 임시테이블을 만들고 rename으로 테이블 교체
CREATE TABLE `TMP_LOAD_20180605` (
  ...
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
ROW_FORMAT=DYNAMIC COMMENT='테스트';

 
바라쿠다엔진은 여러 format이 있는데 테이블의 사용 패턴에 따라 다양하게 설정하면 된다. 해당테이블은 update가 빈번히 일어나서 Dynamic으로 설정하였다.
실시간 데이터 연동테이블이라 Rename으로 교체작업을 진행하였다.


3) unique 인덱스 생성
alter table TMP_LOAD_20180605 add unique index IDX_LOAD_20180605_02 (REGID);

 
잘된다...^^ 이제 성능이슈는 한동안.. byebye...
 

 

반응형

'RDB > mysql' 카테고리의 다른 글

mysql shell script 2  (0) 2019.09.09
Mysql shell script 1  (0) 2019.09.09
Xtrabackup 2.49 설치  (0) 2019.09.06
mysql 5.7 binary 설치 3  (0) 2019.08.30
mysql 5.7 binary 설치 2  (0) 2019.08.28
블로그 이미지

dung beetle

취미는 데이터 수집 직업은 MYSQL과 함께 일하는 DBA의 소소한 일상 이야기

,
반응형

MariaDB는 mysql 의 Clone DB로 mysql과 거의 동일하다 10.3.x 버전부터는 Mysql과 다른 길을 걷고 있기 때문에 10.3.x 버전부터는 적용시 검토가 필요하다.

여기서는 stable 버전중에 mysql 5.7과 호환이 가능한 10.2.26 버전을 설치해본다.

 

1,.파일다운로드 페이지

https://downloads.mariadb.org/mariadb/10.2.26/

 

2. 설치 파일 선택(현재 OS는 CentOS 6.10)


mariadb-10.2.26-linux-systemd-x86_64.tar.gz -> CentOS 7 이상 설치x

mariadb-10.2.26-linux-glibc_214-x86_64.tar.gz (requires GLIBC_2.14+)

 [mysql@test-db ~]$ getconf -a | grep libc
GNU_LIBC_VERSION                   glibc 2.12


--> 2.14보다 아래라서 설치x


mariadb-10.2.26-linux-x86_64.tar.gz --> 설치가능O

 

3. Mariadb-10.2.26 설치

-- 초기설정은 Mysql 5.7과 같다 다른부분만 기술한다.

 #권한su

[root@testdb]# /home/mysql/mariadb/bin/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/home/mysql/mariadb --datadir=/home/mysql/mariadb_data

 

#Trouble shooting 1) 뭐냐 왜 안돼냐..my.cnf 돌려쓰기 실패..
# /data/svc/mariadb/bin/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/data/svc/mariadb --datadir=/data/svc/mariadb_data
Installing MariaDB/MySQL system tables in '/data/svc/mariadb_data' ...
2018-05-14 14:44:21 140143191357216 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2018-05-14 14:44:22 140143191357216 [ERROR] /data/svc/mariadb/bin/mysqld: unknown variable 'innodb_additional_mem_pool_size=32M'
2018-05-14 14:44:22 140143191357216 [ERROR] Aborting
# => innodb_additional_mem_pool_size 주석처리함
#확인: innodb_additional_mem_pool_size was deprecated and has been removed, but innodb_file_format etc
https://mariadb.com/kb/en/library/changes-improvements-in-mariadb-102/

By default, until MariaDB 10.1, MariaDB uses the XtraDB storage engine, a performance enhanced fork of the InnoDB storage engine. For compatibility reasons, the system variables still retain their original innodb prefixes, and where the text in this knowledge base refers to InnoDB, it can usually be understood as referring to the XtraDB fork.
From MariaDB 10.2, InnoDB is the default (see Why MariaDB uses InnoDB instead of XtraDB from MariaDB 10.2).
Note that it is possible to use InnoDB as a plugin in MariaDB 10.1 and before instead of XtraDB. See Using InnoDB instead of XtraDB.
=> 10.2.x 버전부터 MariaDB도 XtraDB가 아니라 innodb를 default로 사용한다.

 

#my.cnf 수정후 다시 설치해본다.

[root@testdb]# ./mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/home/mysql/mariadb --datadir=/home/mysql/mariadb_data

 

Installing MariaDB/MySQL system tables in '/data/svc/mariadb_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:

'/data/svc/mariadb/bin/mysqladmin' -u root password 'new-password'
'/data/svc/mariadb/bin/mysqladmin' -u root -h 172.31.8.62 password 'new-password'

Alternatively you can run:
'/data/svc/mariadb/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 '/data/svc/mariadb' ; /data/svc/mariadb/bin/mysqld_safe --datadir='/data/svc/mariadb_data'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/data/svc/mariadb/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@testdb]#

# 잘된다ㅎㅎ

 

#시작 스크립트 작성
ln -s /home/mysql/mariadb/support-files/mysql.server /home/mysql/mariadb/bin/
ln -s /home/mysql/mariadb/bin/mysql.server /etc/init.d/mysqld

 

[root@testdb]# service mysqld start

Starting MariaDB.180521 16:16:34 mysqld_safe Logging to '/home/mysql/mariadb_logs/error/mysql.err'.
180521 16:16:34 mysqld_safe Starting mysqld daemon with databases from /home/mysql/mariadb_data
..                                                         [  OK  ]

 

#보안설정

[root@testdb]# cd /home/mysql/mariadb/bin

[root@testdb]# ./mysql_secure_installation --basedir=/home/mysql/mariadb

 

print: /home/mysql/mariadb/bin/my_print_defaults

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, 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):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none): [그냥 엔터누른다]
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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
 ... Success!

By default, MariaDB 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
 - 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 MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

[root@testdb]# cd /home/mysql/mariadb/bin
[root@testdb]# cp my_print_defaults mysql mysql_config mysqladmin mysqlbinlog mysqlcheck mysqldump mysqlimport mysqlshow mysqlslap /usr/bin
[root@bin]# chown -Rf root.root my_print_defaults mysql mysql_config mysqladmin mysqlbinlog mysqlcheck mysqldump mysqlimport mysqlshow mysqlslap

 

[root@testdb]# service mysqld stop

 

#mysql 계정으로 접속

[mysql@testdb]# service mysqld start

 

#쉘 접속확인

[mysql@testdb]# mysql -uroot -p

 

 

 

반응형
블로그 이미지

dung beetle

취미는 데이터 수집 직업은 MYSQL과 함께 일하는 DBA의 소소한 일상 이야기

,
반응형

1.my.cnf 설정

 

1-1)신규생성
- 시스템 매모리가 4G 이상일 때 : my-innodb-heavy-4G.cnf
- 시스템 매모리가 1G~2G 일 때 : my-huge.cnf
- 시스템 매모리가 512MB 정도 일 때 : my-large.cnf
- 시스템 매모리가 32M~64M 이상일 때 : my-medium.cnf
- 시스템 매모리가 64M 이하일 때 : my-small.cnf

 

 cp /usr/local/mysql/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf

 

/etc/my-innodb-heavy-4G.cnf

my-innodb-heavy-4G.cnf

 

1-2) 기존 쓰는 my.cnf가 있을 때(my.cnf 파일만 가져와서 복사)

 cp -rp /home/mysql/my.cnf /etc/my.cnf

 

2. mysql 설치

#su 권한 

[root@~]# /home/mysql/mysqldb_bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql

 

#시작 스크립트 등록
[root@~]# cp -rp /home/mysql/mysqldb_bin/support-files/mysql.server ../bin
[root@~]# ln -s /home/mysql/mysqldb_bin/bin/mysql.server /etc/init.d/mysqld

 

#DB server 시작

[root@~]# service mysqld start
Starting MySQL...                                          [  OK  ]

 

#Mysql 보안설정

[root@~]# cd /home/mysql/mysqldb_bin/bin
[root@~]# ./mysql_secure_installation --basedir=/home/mysql/mysqldb_bin --socket=/tmp/mysql.sock

 

...
패스워드 입력 후
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : N

... skipping.

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? (Press y|Y for Yes, any other key for No) : y
- 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? (Press y|Y for Yes, any other key for No) : y
Success..

 

#path 잡기귀찮으면 자주쓰는 것 때려넣는다.

[root@~]# cd /home/mysql/mysqldb_bin/bin

[root@~]# cp my_print_defaults mysql mysql_config mysqladmin mysqlbinlog mysqlcheck mysqldump mysqlimport mysqlshow mysqlslap /usr/bin

[root@~]#cd /usr/bin
[root@~]# chown -Rf root.root my_print_defaults mysql mysql_config mysqladmin mysqlbinlog mysqlcheck mysqldump mysqlimport mysqlshow mysqlslap

 

[root@~]# service mysqld stop

 

#mysql계정으로 접속

[mysql@~]$ service mysqld start
Starting MySQL...                                          [  OK  ]

 

3. mysql shell 접속

 [mysql@~]$ mysql -uroot -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.27-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>

 

 

 

반응형

'RDB > mysql' 카테고리의 다른 글

mysql shell script 2  (0) 2019.09.09
Mysql shell script 1  (0) 2019.09.09
Xtrabackup 2.49 설치  (0) 2019.09.06
varchar 255가 넘는 인덱스 추가  (0) 2019.09.05
mysql 5.7 binary 설치 2  (0) 2019.08.28
블로그 이미지

dung beetle

취미는 데이터 수집 직업은 MYSQL과 함께 일하는 DBA의 소소한 일상 이야기

,
반응형

1. 설치 파일 다운로드
- mysql 홈페이지에 가서 다운로드 받으면 된다.
  당연히 오라클사에서 인수했기 때문에 이제는 오라클 계정이 있어야 다운로드가 가능하다.
  mysql 도 오라클처럼 standard, enterprise 버전이 있다.
  무료 standard 버전은 여기서는 communtiy 라고 한다.
  장비에 설치된 OS에 맞게 다운로드 한다.
  현재 유휴장비의 OS는 CentOS 6.10 64bit이므로 맞춰 다운받는다.
  GILBC 버전체크도 중요하다. 2.12 인지 확인하고 2.14이상일 경우 2.12버전을 설치해도 상관없지만
  C++ 라이브러리 함수의 더 많은 사용(?) 을 하려면 버전에 맞는 binary 파일을 다운 받는 것이 좋다.

 

다운로드 경로: https://dev.mysql.com/downloads/mysql/5.7.html

 

 

 

2. 파일 전송

- 아마 21 FTP포트는 못 쓸 것이다. 22포트를 쓸 수 있는 winscp나 그런 걸 통해서 장비로 파일 전송한다.

 

3. mysql 계정생성

#su 권한 --mysql계정으로 쉘 접속이 필요할 경우(replication 관리필요시)

groupadd mysql

useradd -d /home/mysql -s /bin/bash mysql

 

#su 권한 --쉘 접속 필요 x

groupadd mysql

useradd -d /home/mysql -s /sbin/nologin mysql

 

4. mysql 디렉토리 경로설정

mkdir {backup,mysqldb_bin,mysqldb_data,mysqldb_logs}

cd /home/mysql/mysqldb_logs

mkdir {binary,error,relay,slow}

 

5. 압축해제

#su 권한

cd /home/mysql/backup

tar -zvxf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

..

mv mysql-5.7.27 /home/mysql/mysqldb_bin

chown -Rf mysql:mysql /home/mysql

반응형

'RDB > mysql' 카테고리의 다른 글

mysql shell script 2  (0) 2019.09.09
Mysql shell script 1  (0) 2019.09.09
Xtrabackup 2.49 설치  (0) 2019.09.06
varchar 255가 넘는 인덱스 추가  (0) 2019.09.05
mysql 5.7 binary 설치 3  (0) 2019.08.30
블로그 이미지

dung beetle

취미는 데이터 수집 직업은 MYSQL과 함께 일하는 DBA의 소소한 일상 이야기

,