[네이버클라우드캠프] - 4일차 ( RockyLlinux, ubuntu mysql-user 생성, 연결, 실습 )

holy one·2023년 4월 27일
0

4.27까지 실습은 RockyLinux 에서 실습

  • 많이 쓰는 컨트롤 방법
    systemctl start [프로세스]
    systemctl stop [프로세스]
    systemctl status [프로세스]
    systemctl restart [프로세스]

sqlite 설치 및 실습

  • dnf 형식으로 다운
[root@nc7 /]# dnf -y install sqlite		- 설치코드
Last metadata expiration check: 0:59:35 ago on Thu Apr 27 10:01:15 2023.
Dependencies resolved.
================================================================================================================
 Package                    Architecture          Version                        Repository                Size
================================================================================================================
Installing:
 sqlite                     x86_64                3.34.1-6.el9_1                 appstream                748 k
Upgrading:
 sqlite-libs                x86_64                3.34.1-6.el9_1                 baseos                   619 k

Transaction Summary
================================================================================================================
Install  1 Package
Upgrade  1 Package

Total download size: 1.3 M
Downloading Packages:
(1/2): sqlite-3.34.1-6.el9_1.x86_64.rpm                                         4.8 MB/s | 748 kB     00:00
(2/2): sqlite-libs-3.34.1-6.el9_1.x86_64.rpm                                    3.8 MB/s | 619 kB     00:00
----------------------------------------------------------------------------------------------------------------
Total                                                                           1.0 MB/s | 1.3 MB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                        1/1
  Upgrading        : sqlite-libs-3.34.1-6.el9_1.x86_64                                                      1/3
  Installing       : sqlite-3.34.1-6.el9_1.x86_64                                                           2/3
  Cleanup          : sqlite-libs-3.34.1-5.el9.x86_64                                                        3/3
  Running scriptlet: sqlite-libs-3.34.1-5.el9.x86_64                                                        3/3
  Verifying        : sqlite-3.34.1-6.el9_1.x86_64                                                           1/3
  Verifying        : sqlite-libs-3.34.1-6.el9_1.x86_64                                                      2/3
  Verifying        : sqlite-libs-3.34.1-5.el9.x86_64                                                        3/3

Upgraded:
  sqlite-libs-3.34.1-6.el9_1.x86_64
Installed:
  sqlite-3.34.1-6.el9_1.x86_64

Complete!


[root@nc7 /]# sqlite3
SQLite version 3.34.1 2021-01-20 14:10:07
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> show database;
Error: near "show": syntax error
sqlite>								- 접속 완료

sqlite> .open myDB
sqlite> .mode col
sqlite> .head on

sqlite> create table score(name, kor, mat, eng);
sqlite> insert into score values("kim", 40, 50, 60);
sqlite> insert into score values("chio", 50, 90, 30);

sqlite> select * from score;		- 쿼리가 입력된  table  table 출력
name  kor  mat  eng
----  ---  ---  ---
kim   40   50   60
chio  50   90   30
sqlite> .q
  • 사이트 방문하여 설치
[root@nc7 /down]# wget https://sqlite.org/2023/sqlite-autoconf-3410200.tar.gz

[root@nc7 /down]# tar xvf sqlite-autoconf-3410200.tar.gz -  압축 해제
[root@nc7 /down]# l
total 3060
drwxrwxr-x. 3 blue blue    4096 Mar 22 22:45 sqlite-autoconf-3410200/
-rw-r--r--. 1 root root 3125545 Mar 23 01:33 sqlite-autoconf-3410200.tar.gz

[root@nc7 /down/sqlite-autoconf-3410200]# ls	- 경로 변경 확인
INSTALL            Makefile.msc  compile       configure.ac  missing    sqlite3.h      sqlite3rc.h
Makefile.am        README.txt    config.guess  depcomp       shell.c    sqlite3.pc.in  tea
Makefile.fallback  Replace.cs    config.sub    install-sh    sqlite3.1  sqlite3.rc
Makefile.in        aclocal.m4    configure     ltmain.sh     sqlite3.c  sqlite3ext.h

- 설치 위치 변경 및 환경 설정
[root@nc7 /down/sqlite-autoconf-3410200]# ./configure --prefix=/sql	
[root@nc7 /down/sqlite-autoconf-3410200]# make install	- 설치 명령 컴파일하고 빌드

 /usr/bin/mkdir -p '/sql/bin'

- 한방에 하는 법
[root@nc7 /down/sqlite-autoconf-3410200]# ./configure --prefix=/s3 \
> && make && make install

[root@nc7 /down/sqlite-autoconf-3410200]# ls /
afs  boot  dev   etc   lib    media  myDB  prfile  root  sbin  srv  tmp  var
bin  data  down  home  lib64  mnt    opt   proc    run   sql   sys  usr
[root@nc7 /down/sqlite-autoconf-3410200]# ls / | grep sql
sql

[root@nc7 /]# cd sql

[root@nc7 /sql]# ls bin/		- sqlite 폴더 존재 확인
sqlite3

[root@nc7 /sql]# /sql/bin/sqlite3		- 실행
SQLite version 3.41.2 2023-03-22 11:56:21
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
mkdir /down2 && cd /down2
설치위치 /z3
p169

필수 
sqlite> . open adb
sqlite> .header on
sqlite> .mode column
sqlite> .table


sqlite> CREATE TABLE Man(			- 테이블 설정
   ...> name char(20),
   ...> age int);

sqlite> insert into Man VALUES ("kim",20);		- 테이블에 쿼리 입력
sqlite> insert into Man VALUES ("kin",21);
sqlite> insert into Man VALUES ("ki",22);

sqlite> SELECT * from Man;		-쿼리 입력된 Man 테이블 출력
kim|20
kin|21
ki|22

sqlite>.quit
  • RockyLinux에서 실습

Mysql 실습

root@nc7:~# mysql				-  mysql 접속 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.32-0ubuntu0.22.04.2 (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> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2023-04-28 16:56:34 |
+---------------------+
1 row in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

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 \					- root 접속 허가
    -> with mysql_native_password by 'jj';
Query OK, 0 rows affected (0.01 sec)

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

mysql> grant all privileges on samDB.* to mysam@localhost;		- samDB 권한 해제 = 모든 사용자 사용 가능
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;										- 현재 사용중인 MySQL의 캐시 삭제 및 초기화 
Query OK, 0 rows affected (0.00 sec)


- 다른 계정 접속
7 sam@nc7 17:01:23 ~]$ mysql -u mysam -p						- SQL 의 mysam 계정으로 접속
Enter password:		'j'
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.32-0ubuntu0.22.04.2 (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 samDB;												- database 접속
Database changed

mysql> create table Man (										- table 생성
    -> 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("이강인", 23);
Query OK, 1 row affected (0.00 sec)

mysql> select * from Man;										- 쿼리 입력된 table 출력
+-----------+------+
| name      | age  |
+-----------+------+
| 손흥민    |   32 |
| 이강인    |   23 |
+-----------+------+
2 rows in set (0.00 sec)

mysql>
  • 자주 등장하는 에러
1.
[root@nc7 /]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

2.
Error 1064 (42000): You have an error in your SQL syntax: check the manual the corresponds to your MYSQL server version for the right syntax to use near ,,,
  • 해결
1.
[root@nc7 /]# systemctl start mysqld = 시작 명령어
			   └> d : daemon
               
2. 
syntax 에러는 대체로 오타일 확률이 농후하다. 오타를 수정해보자 
ex) 
Error 1064 (42000): You have an error in your SQL syntax: check the manual the corresponds 
to your MYSQL server version for the right syntax to use near 'privilegas' at the line 1 
= 1번쨰 줄의  privilegas의 오타를 privileges로 수정하면 OK구문을 받을수 있다.
  • root pw 설정 오류
root@il7@10:20:12:~# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  • 해결
profile
☁️ 좋아요!

0개의 댓글