본문 바로가기
코딩

mariadb 구성하기

by Doldam Alice 2023. 1. 27.
300x250

# apt-get update

# apt-get install mariadb-server
# systemctl status mariadb

# ps -ef |grep mysql
mysql      42298       1  0 17:05 ?        00:00:02 /usr/sbin/mysqld

# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 36
Server version: 10.3.37-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+



MariaDB [(none)]> create database aiot_db ;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> show databases ;
+--------------------+
| Database           |
+--------------------+
| aiot_db            |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.000 sec)



MariaDB [(none)]> use aiot_db ;
Database changed
MariaDB [aiot_db]> show tables ;
Empty set (0.000 sec)

MariaDB [aiot_db]> create table aiot_info (ID int, NAME varchar(20), DEPT varchar(25)) default charset=utf8 ;
Query OK, 0 rows affected (0.015 sec)

MariaDB [aiot_db]> create table aiot_grade (ID int, MATH int, English int ) ;
Query OK, 0 rows affected (0.006 sec)

MariaDB [aiot_db]> show tables ;
+-------------------+
| Tables_in_aiot_db |
+-------------------+
| aiot_grade        |
| aiot_info         |
+-------------------+
2 rows in set (0.000 sec)


MariaDB [aiot_db]> explain aiot_info ;
+-------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| ID        | int(11)     | YES  |     | NULL    |       |
| NAME  | varchar(20) | YES  |     | NULL    |       |
| DEPT    | varchar(25) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.001 sec)

MariaDB [aiot_db]> explain aiot_grade
+---------+---------+------+-----+---------+-------+
| Field   | Type    | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+-------+
| ID      | int(11) | YES  |     | NULL    |       |
| MATH    | int(11) | YES  |     | NULL    |       |
| English | int(11) | YES  |     | NULL    |       |
+---------+---------+------+-----+---------+-------+
3 rows in set (0.001 sec)


MariaDB [aiot_db]> insert into aiot_info values (1000, '유미', 'Computer science') ;
Query OK, 1 row affected (0.008 sec)

MariaDB [aiot_db]> insert into aiot_info value (1001, '전도준', 'Game') ;
Query OK, 1 row affected (0.008 sec)

MariaDB [aiot_db]> insert into aiot_grade value (1000, 50, 100 ) ;
Query OK, 1 row affected (0.008 sec)

MariaDB [aiot_db]> insert into aiot_grade value (1001, 70, 80 ) ;
Query OK, 1 row affected (0.008 sec)


MariaDB [aiot_db]> select * from aiot_info ;
+------+-----------+------------------+
| ID   | NAME      | DEPT             |
+------+-----------+------------------+
| 1000 | 유미      | Computer science |
| 1001 | 전도준    | Game             |
+------+-----------+------------------+
2 rows in set (0.000 sec)

MariaDB [aiot_db]> select * from aiot_grade ;
+------+------+---------+
| ID   | MATH | English |
+------+------+---------+
| 1000 |   50 |     100 |
| 1001 |   70 |      80 |
+------+------+---------+


MariaDB [aiot_db]> select NAME from aiot_info where ID=1000 ;
+--------+
| NAME   |
+--------+
| 유미   |
+--------+

MariaDB [aiot_db]> select ID from aiot_grade where English>=90 ;
+------+
| ID   |
+------+
| 1000 |
+------+
MariaDB [aiot_db]> update aiot_grade set MATH=80 where ID=1000 ;
Query OK, 1 row affected (0.009 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [aiot_db]> select * from aiot_grade
    -> ;
+------+------+---------+
| ID   | MATH | English |
+------+------+---------+
| 1000 |   80 |     100 |
| 1001 |   70 |      80 |
+------+------+---------+
2 rows in set (0.000 sec)



MariaDB [aiot_db]> exit
Bye


# systemctl status mariadb
# systemctl stop mariadb

# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
# systemctl start mariadb



# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 37
Server version: 10.3.37-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases ;
+--------------------+
| Database           |
+--------------------+
| aiot_db            |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.000 sec)

MariaDB [(none)]> use aiot_db ;
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
MariaDB [aiot_db]> select * from aiot_grade ;
+------+------+---------+
| ID   | MATH | English |
+------+------+---------+
| 1000 |   80 |     100 |
| 1001 |   70 |      80 |
+------+------+---------+
2 rows in set (0.000 sec)

300x250

댓글