。゚(*´□`)゚。

코딩의 즐거움과 도전, 그리고 일상의 소소한 순간들이 어우러진 블로그

[네이버클라우드] 클라우드 기반의 개발자 과정 7기/리눅스

[리눅스]mysql 접속

quarrrter 2023. 5. 7. 01:34

루트에서 mysql 계정 생성 후 사용자계정에서 접속하기 

root 에서 

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 \                mysql 비번 바꿈
    -> with mysql_native_password by 'jj'
    -> ;
Query OK, 0 rows affected (0.01 sec)

mysql> create user myk2@localhost identified \                 mysql myk2 계정을 만듬
    -> with mysql_native_password by 'j';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on k2DB.* to myk2@localhost;          k2DB에 대해 모든 권한 허용
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)



k2에서
k2@psh:~$ mysql -u myk2 -p
비번 입력 j 접속 ~ 


mysql> create database k2DB
    -> ;
Query OK, 1 row affected (0.00 sec)

mysql> use k2DB
Database changed
mysql> show table;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1


mysql> create table Man(
    -> name char(20),
    -> age int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into Man values('손흥민', 32);
Query OK, 1 row affected (0.01 sec)

mysql> insert into Man values('이강인', 25);
Query OK, 1 row affected (0.01 sec)

mysql> select * from Man;
+-----------+------+
| name      | age  |
+-----------+------+
| 손흥민    |   32 |
| 이강인    |   25 |
+-----------+------+
2 rows in set (0.00 sec)