본문 바로가기
네이버클라우드/Linux

Linux 9일차 (2023-05-04) 네이버클라우드서버 설정하기 - mysql 계정 만들기

by prometedor 2023. 5. 4.

mysql 계정 만들기

root 에서 사용자 생성

root@ysy:~# useradd sy
root@ysy:~# passwd sy
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is a palindrome
Retype new password:
passwd: password updated successfully

 

root 에서 mysql 설정

root@ysy:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.41-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2023, 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> alter user root@localhost identified
    -> with mysql_native_password by 'jj';
Query OK, 0 rows affected (0.00 sec)

mysql> create user mysy@localhost identified
    -> with mysql_native_password by 'j';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on syDB.* to mysy@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

 

생성한 사용자로 로그인하여 데이터베이스 생성

sy@ysy:~$ mysql -u mysy -p  --> 생성한 사용자(sy)가 mysql 을 사용할 수 있도록 설정

--> MySQL 데이터베이스에 mysy 사용자로 로그인하는 데 사용됨
    ㄴ -u  옵션 : MySQL에 로그인할 사용자 이름을 지정
    ㄴ -p 옵션 : 암호를 입력하도록 요청

Enter password:  
--> (root에서 mysy@localhost identified with mysql_native_password by 'j'; 로 설정했으므로 비밀번호 : j)

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.32-0ubuntu4 (Ubuntu)

Copyright (c) 2000, 2023, 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> create database syDB;  --> syDB 라는 이름으로 데이터베이스를 설정함
Query OK, 1 row affected (0.00 sec)

mysql> use syDB;  --> syDB 를 사용하겠다
Database changed
mysql> show tables;  --> table 목록 보기
Empty set (0.00 sec)
mysql> exit
Bye