MySql 기본설치
Remark:
MySql 의 최신 버전 version: 8.0.23 을 설치해 보자.
1. Download the MySQL repositories
|
1 2 3 |
# sudo wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm |
2. Install MySQL packages
|
1 2 3 |
# sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm |
3. Install MySQL
|
1 2 3 |
# sudo yum install mysql-server |
4. Start MySQL
|
1 2 3 |
# sudo systemctl start mysqld |
5. Start MySQL
|
1 2 3 |
# sudo systemctl status mysqld |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# sudo systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2021-01-19 11:19:30 KST; 2h 32min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 3137 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 3214 (mysqld) Status: "Server is operational" CGroup: /system.slice/mysqld.service └─3214 /usr/sbin/mysqld |
5. MySQL Root User temporary root password check
|
1 2 3 |
# sudo grep 'password' /var/log/mysqld.log |
|
1 2 3 4 |
# sudo grep 'password' /var/log/mysqld.log 2021-01-19T02:18:21.839765Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: &12323232 |
6. mysql_secure_installation
|
1 2 3 |
sudo mysql_secure_installation |
root 계정이 비밀번호 인증이 아니라
auth_socket방식으로 설정됨Ubuntu에서
apt install mysql-server로 설치하면
MySQL root 계정은 기본적으로 비밀번호 로그인을 막고,
OS의root사용자만 접속 가능하도록 설정됩니다.즉,
- ❌
mysql -u root -p→ 실패- ✅
sudo mysql→ 성공
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
localhost@localhost:~$ sudo mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Skipping password set for root as authentication with auth_socket is used by default. If you would like to use password authentication instead, this can be done with the "ALTER_USER" command. See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information. 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) : n ... skipping. 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) : No ... 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. All done! |
7. Root remote allow authority (root % )
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
localhost@localhost:~$ sudo mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 19 Server version: 8.4.7-0localhost0.25.10.3 (localhost) Copyright (c) 2000, 2025, Oracle and/or its affiliates. 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> 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 mysql> SELECT user, host, plugin -> FROM mysql.user -> WHERE user = 'root'; +------+-----------+-------------+ | user | host | plugin | +------+-----------+-------------+ | root | localhost | auth_socket | +------+-----------+-------------+ 1 row in set (0.00 sec) |
plugin 값이 auth_socket 되어 있고,
IP 로 세팅하면 host mysql 로그인이 되지 않음
🟢 방법 1️⃣ (가장 권장) : sudo mysql 사용
보안적으로 가장 안전한 기본 방식입니다.
|
1 2 3 4 |
sudo mysql |
서버 운영 환경에서는 이 방법을 그대로 쓰는 게 일반적입니다.
🟡 방법 2️⃣ : root 계정을 비밀번호 로그인 가능하게 변경
로컬 개발환경에서 편할 때 사용
① MySQL 접속
|
1 2 3 4 |
sudo mysql |
② 인증 방식 변경 + 비밀번호 설정
|
1 2 3 4 5 6 7 8 |
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '새비밀번호'; FLUSH PRIVILEGES; |
에러시 -> mysql_native_password 안된상태, 기존 caching_sha2_password 사용
123 ERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded
|
1 2 3 |
mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '비밀번호'; |
③ 접속 테스트
|
1 2 3 4 |
mysql -u root -p |
🔴 방법 3️⃣ : root 대신 별도 관리자 계정 생성 (추천)
운영 환경에서는 이 방법이 베스트
|
1 2 3 4 5 6 7 8 9 10 |
CREATE USER 'admin'@'localhost' IDENTIFIED BY '비밀번호'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES; |
접속:
|
1 2 3 |
mysql -u admin -p |
8. Remote allow configuration (bind-address )
|
1 2 3 |
# sudo vi /etc/mysql/mysql.conf.d/mysql.cnf |
|
1 2 3 4 5 6 |
# 주석처리 #bind-address = 127.0.0.1 #mysqlx-bind-address = 127.0.0.1 |
9. 방화벽 오픈 및 Mysql Restart
|
1 2 3 4 5 |
# sudo systemctl restart mysql # sudo ufw allow mysql |
10. MySQL Workbench Connect test

