yum 레포지토리를 열어서 mariadb
저장소를 추가합니다.
$ sudo vi /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/rhel8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
$ sudo dnf update
$ sudo dnf install mariadb-server mariadb
자동 시작 설정인지 확인
$ systemctl list-unit-files | grep -E 'mariadb|mysql'
mariadb.service disabled
mariadb@.service disabled
자동 시작을 활성화 +
mysql.service
명령을 사용할 때 실제로는 mariadb.service
가 실행되도록 심볼릭링크를 연결합니다.
$ sudo systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
$ sudo systemctl start mariadb
설치 y5 번
참고 https://bluewins.tistory.com/entry/Rocky-Linux-MariaDB-%EC%84%A4%EC%B9%98
$ sudo 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!
$ cd /etc/my.cnf.d
$ vi server.cnf
[mysqld]
bind-address = 0.0.0.0
MariaDB [(none)]> SELECT Host,User,plugin,authentication_string FROM mysql.user;
+-----------+-------------+-----------------------+-------------------------------------------+
| Host | User | plugin | authentication_string |
+-----------+-------------+-----------------------+-------------------------------------------+
| localhost | mariadb.sys | mysql_native_password | |
| localhost | root | mysql_native_password | *0D8D4B736322D912D44598ECDD2337F5C9F6F76B |
| localhost | mysql | mysql_native_password | invalid |
+-----------+-------------+-----------------------+-------------------------------------------+
3 rows in set (0.001 sec)
MariaDB [(none)]> SELECT User, Host FROM mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
+-------------+-----------+
3 rows in set (0.001 sec)
MariaDB [(none)]> create user 'PIO'@'%' identified by 'PIO01';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> select user, host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| PIO | % |
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
+-------------+-----------+
4 rows in set (0.001 sec)
MariaDB [(none)]> show grants for 'PIO'@'%';
+----------------------------------------------------------------------------------------------------+
| Grants for PIO@% |
+----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `PIO`@`%` IDENTIFIED BY PASSWORD '*EA36E96BF42F00DA3782DB080157F40614897D28' |
+----------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
MariaDB [(none)]> grant select on mysql.user to 'PIO'@'%';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)
포트 변경 방법 및 권한 변경 참고
https://4urdev.tistory.com/82
https://ko.linux-console.net/?p=2320
SHOW GRANTS FOR 'PIO'@'%';
GRANT ALL PRIVILEGES ON ICCOPY.* TO 'PIO'@'%';
FLUSH PRIVILEGES;
CREATE DATABASE ICCOPY DEFAULT CHARACTER SET UTF8;
원인은 패킷 사이즈가 부족하기 때문입니다.
$ cd /etc/my.cnf.d
$ vi server.cnf
[mysqld]
max_allowed_packet = 512M
lower_case_table_names=1
아래와 같이 utf-8이 아닐경우 한글이 ?? 로 출력될 수 있다.
MariaDB [(none)]> show variables like 'c%'ㄴㄷ;
+----------------------------------+----------------------------+
| Variable_name | Value |
+----------------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| check_constraint_checks | ON |
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
| column_compression_threshold | 100 |
| column_compression_zlib_level | 6 |
| column_compression_zlib_strategy | DEFAULT_STRATEGY |
| column_compression_zlib_wrap | OFF |
| completion_type | NO_CHAIN |
| concurrent_insert | AUTO |
| connect_timeout | 10 |
| core_file | OFF |
+----------------------------------+----------------------------+
my.cnf 또는 my.ini 에 다음줄 추가후 DB서버 재시작
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
시작
systemctl start mysqld
정지
systemctl stop mysqld
재시작
systemctl restart mysqld
상태
systemctl status mysqld
쿼리문을 통해서 인코딩을 변경할 경우
ALTER DATABASE `[dbname]` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER DATABASE `[dbname]` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
테이블만 설정하려면
ALTER TABLE `[tablename]` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
개인적으로 설정파일 변경후 재시작이 한번에 해결됐습니다.