어제와 똑같이 살면서 다른 미래를 기대하지 말자

[CentOS7] MariaDB 설치 10.2.x 본문

IT관심분야/Linux

[CentOS7] MariaDB 설치 10.2.x

플랜액터 2018. 2. 14. 18:08

1. MariaDB 설치

1) YUM REPO 등록

https://mariadb.com/kb/en/library/mariadb-package-repository-setup-and-usage/

# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

2) 설치

# yum install mariadb-server


2. MariaDB 실행

# systemctl start mariadb

# systemctl enable mariadb


3. MariaDB 초기세팅

# mysql_secure_installation

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):

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!


4. MariaDB cnf 파일설정

# systemctl stop mariadb

1) 기본 data 디렉토리 변경 시

# mkdir /db/mysql

# chown --reference=/var/lib/mysql /db/mysql && chmod --reference=/var/lib/mysql /db/mysql

or ( chown mysql:mysql -R /db/mysql && chmod 755 /db/mysql )

# mv /var/lib/mysql/* /db/mysql/

# rm -rf /var/lib/mysql

2) server.cnf 설정

# vi /etc/my.cnf.d/server.cnf

#

# These groups are read by MariaDB server.

# Use it for options that only the server (but not clients) should see

#

# See the examples of server my.cnf files in /usr/share/mysql/

#


# this is read by the standalone daemon and embedded servers

[server]


# this is only for the mysqld standalone daemon

[mysqld]

datadir=/db/mysql # mysql 기본 data 디렉토리 변경

socket=/db/mysql/mysql.sock # socket 경로 변경

character-set-server=utf8


#

# * Galera-related settings

#

[galera]

# Mandatory settings

#wsrep_on=ON

#wsrep_provider=

#wsrep_cluster_address=

#binlog_format=row

#default_storage_engine=InnoDB

#innodb_autoinc_lock_mode=2

#

# Allow server to accept connections on all interfaces.

#

#bind-address=0.0.0.0

#

# Optional setting

#wsrep_slave_threads=1

#innodb_flush_log_at_trx_commit=0


# this is only for embedded server

[embedded]


# This group is only read by MariaDB servers, not by MySQL.

# If you use the same .cnf file for MySQL and MariaDB,

# you can put MariaDB-only options here

[mariadb]


# This group is only read by MariaDB-10.1 servers.

# If you use the same .cnf file for MariaDB of different versions,

# use this group for options that older servers don't understand

[mariadb-10.1]

3) mysql-client.conf 설정

# vi /etc/my.cnf.d/mysql-clients.cnf

#

# These groups are read by MariaDB command-line tools

# Use it for options that affect only one utility

#

[mysql]

default-character-set=utf8

socket=/db/mysql/mysql.sock # 설정하지 않을경우 mysql 접속 시 에러발생

# port=3306 (기본포트 변경 시 사용)


[mysql_upgrade]

[mysqladmin]

[mysqlbinlog]

[mysqlcheck]

[mysqldump]

[mysqlimport]

[mysqlshow]

[mysqlslap]


5. mariadb 접속 및 설정확인

# mysql -uroot -p

1) 기본 디렉토리 경로설정 확인

MariaDB [(none)]> select @@datadir;

+------------+

| @@datadir  |

+------------+

| /db/mysql/ |

+------------+


2) DB 버전 확인

MariaDB [(none)]> select version();

+-----------------+
| version()       |
+-----------------+
| 10.2.13-MariaDB |
+-----------------+

3) 캐릭터 셋 확인

MariaDB [(none)]> show variables like 'c%';

+--------------------------+----------------------------+

| Variable_name            | Value                      |

+--------------------------+----------------------------+

| character_set_client     | utf8                       |

| character_set_connection | utf8                       |

| character_set_database   | utf8                       |

| character_set_filesystem | binary                     |

| character_set_results    | utf8                       |

| character_set_server     | utf8                       |

| character_set_system     | utf8                       |

| character_sets_dir       | /usr/share/mysql/charsets/ |

| check_constraint_checks  | ON                         |

| collation_connection     | utf8_general_ci            |

| collation_database       | utf8_general_ci            |

| collation_server         | utf8_general_ci            |

| completion_type          | NO_CHAIN                   |

| concurrent_insert        | AUTO                       |

| connect_timeout          | 10                         |

+--------------------------+----------------------------+


4) 제공 가능한 엔진 확인

MariaDB [(none)]> show engines;

+----------------------------+-------+-------------------------------------------------------------------+--------------+------+-----------+
| Engine                         | Support | Comment                                                               | Transactions | XA   | Savepoints |
+----------------------------+-------+-------------------------------------------------------------------+--------------+------+-----------+
| CSV                            | YES     | CSV storage engine                                                      | NO           | NO   | NO         |
| MRG_MyISAM               | YES     | Collection of identical MyISAM tables                               | NO           | NO   | NO         |
| MyISAM                       | YES     | MyISAM storage engine                                                | NO           | NO   | NO         |
| SEQUENCE                   | YES     | Generated tables filled with sequential values                     | YES          | NO   | YES        |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                                    | NO           | NO   | NO         |
| MEMORY                     | YES     | Hash based, stored in memory, useful for temporary tables   | NO           | NO   | NO         |
| Aria                            | YES     | Crash-safe tables with MyISAM heritage                            | NO           | NO   | NO         |
| InnoDB                       | DEFAULT | Supports transactions, row-level locking, foreign keys .......   | YES          | YES  | YES        |
+----------------------------+---------+-----------------------------------------------------------------+--------------+------+-----------+


Comments