mariaDB

Published by onesixx on

설치 on Docker

https://onesixx.com/mysql-docker/

설치 on macbook

brew install mysql

설정

Homebrew로 설치한 거라, mysql.server대신 brew services [command] mariadb 사용

~$➜  brew services start mariadb
==> Successfully started `mariadb` (label: homebrew.mxcl.mariadb)


~$➜ mysql.server start
Starting MariaDB
210809 21:51:20 mysqld_safe Logging to '/usr/local/var/mysql/sixxMac.err'.
.210809 21:51:20 mysqld_safe Starting mariadbd daemon with databases from /usr/local/var/mysql
 SUCCESS!
~$➜ mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] Y
ERROR 1146 (42S02) at line 1: Table 'mysql.global_priv' doesn't exist
 ... Failed!

By default, MariaDB 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? [Y/n] 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? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
~$➜  mariadb -uroot -p
~$➜  mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \\g.
Your MariaDB connection id is 9
Server version: 10.5.9-MariaDB Homebrew

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)]>
MariaDB [(none)]> status
--------------
mysql  Ver 15.1 Distrib 10.5.9-MariaDB, for osx10.16 (x86_64) using readline 5.1

Connection id:\t\t9
Current database:
Current user:\t\troot@localhost
SSL:\t\t\tNot in use
Current pager:\t\tless
Using outfile:\t\t''
Using delimiter:\t;
Server:\t\t\tMariaDB
Server version:\t\t10.5.9-MariaDB Homebrew
Protocol version:\t10
Connection:\t\tLocalhost via UNIX socket
Server characterset:\tutf8mb4
Db     characterset:\tutf8mb4
Client characterset:\tutf8
Conn.  characterset:\tutf8
UNIX socket:\t\t/tmp/mysql.sock
Uptime:\t\t\t4 hours 54 min 29 sec

Threads: 1  Questions: 14  Slow queries: 0  Opens: 20  Open tables: 13  Queries per second avg: 0.000
--------------
MariaDB [(none)]> 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
MariaDB [mysql]> select user, host  from user;
+---------+-----------+
| user    | host      |
+---------+-----------+
| root    | 127.0.0.1 |
| root    | ::1       |
| onesixx | localhost |
| root    | localhost |
+---------+-----------+
4 rows in set (0.000 sec)
MariaDB [(none)]> exit
Bye
~$➜ brew services stop mariadb
Stopping `mariadb`... (might take a while)
==> Successfully stopped `mariadb` (label: homebrew.mxcl.mariadb)



MariaDB [(none)]> exit
Bye
~$➜  mysql.server stop

ERROR! MariaDB is not running, but PID file exists

Homebrew로 설치한 거라, mysql.server대신 brew services [command] mariadb 사용

~$➜  ps aux | grep mysql
onesixx           3215   0.0  0.0  4282312    160 s001  S     9:51PM   0:00.02 /bin/sh /usr/local/Cellar/mariadb/10.5.9/bin/mysqld_safe --datadir=/usr/local/var/mysql --pid-file=/usr/local/var/mysql/sixxMac.pid
onesixx           3292   0.0  0.0  4830224   2800 s001  S     9:51PM   0:00.37 /usr/local/Cellar/mariadb/10.5.9/bin/mariadbd --basedir=/usr/local/Cellar/mariadb/10.5.9 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mariadb/10.5.9/lib/plugin --log-error=/usr/local/var/mysql/sixxMac.err --pid-file=/usr/local/var/mysql/sixxMac.pid
onesixx           3761   0.0  0.0  4259000    220 s001  R+    2:52AM   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn mysql

~$➜  sudo kill 3215 3292

DB Client

DBeaver ..

datafile 위치

https://www.lesstif.com/pages/viewpage.action?pageId=17105786

show variables like 'datadir';

# Variable_name, Value
‘datadir’, ‘/var/lib/mysql/’

MySQL 테이블 및 데이타베이스 크기 알아내기

SELECT TABLE_NAME AS 'Tables',
       round(((data_length + index_length) / 1024 / 1024), 2) 'Size in MB'
FROM information_schema.TABLES
WHERE table_schema = "wordpress"
ORDER BY (data_length + index_length) DESC;

MySQL 서버 접속

mysql -u root -p

Password는 yml 파일에서 설정한 MYSQL_ROOT_PASSWORD 값

DB 및 사용자 생성

CREATE USER 'scott'@'%' IDENTIFIED BY 'tiger';

GRANT ALL PRIVILEGES ON *.* TO 'scott'@'%';

flush privileges;

quit
-- auto-generated definition
create table users
(
    id              int auto_increment        primary key,
    status          enum ('active', 'deleted', 'blocked') default 'active'          not null,
    email           varchar(255)                                                    null,
    pw              varchar(2000)                                                   null,
    name            varchar(255)                                                    null,
    phone_number    varchar(20)                                                     null,
    profile_img     varchar(1000)                                                   null,
    sns_type        enum ('FB', 'G', 'K', 'Email')                                  null,
    marketing_agree tinyint(1)                            default 0                 null,
    updated_at      datetime                              default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
    created_at      datetime                              default CURRENT_TIMESTAMP not null
);

DB Server 외부 접속 테스트

  • MySQL Workbench GUI 환경에서 접속 테스트
IP: public IP 혹은 localhost
PORT: 3306
USER: jason
PASSWORD: password
Categories: Ubuntu

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x