티스토리 뷰

Database/Mysql

MySQL 실행 및 접속

DevES 2015. 7. 11. 23:19

1.MySQL 실행하기

MySQL 경로는 /usr/local/Cellar/mysql/5.6.25/

MySQL을 실행해보자

/usr/local/Cellar/mysql/5.6.25/support-files

EminentStarui-MacBook-Pro:support-files eminentstar$ mysql.server start


Starting MySQL

. SUCCESS! 


2.MySQL 접속하기

보통은 커맨드라인 어디서든 mysql로 로그인하면 된다. 하지만 그냥 로그인하면 권한이 없는 경우가 많다. 그래서 일단 root로 로그인하자. 맥에 처음 mysql을 깔았다면 root는 비밀번호 없이도 로컬에서 접속이 가능할 것이다.

EminentStarui-MacBook-Pro:support-files eminentstar$ mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.25 Homebrew


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


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> 


위와 같이 나온다면 일단 접속은 성공한거다.

*사용할 DB 만들기

mysql> create database testdb;

Query OK, 1 row affected (0.00 sec)

그리고 꼭 캐릭터셋을 확인해야함. mysql 설치후 따로 캐릭터셋(charset)을 설정하지 않았다면 latin1으로 설정되는데 latin1 캐릭터셋을 쓰면 한글은 당연히 안되고 몇몇 특수문자 사용시 db에서 입력이 안되는 경우가 허다. 그래서 반드시 utf-8로 설정되어 있는지 확인. 확인 방법은 아래와 같다.

mysql> show create database testdb;

+----------+-----------------------------------------------------------------+

| Database | Create Database                                                 |

+----------+-----------------------------------------------------------------+

| testdb   | CREATE DATABASE `testdb` /*!40100 DEFAULT CHARACTER SET utf8 */ |

+----------+-----------------------------------------------------------------+

1 row in set (0.00 sec)



*MySQL 기본 캐릭터셋 설정하기
MySQL에서 설정파일을 읽는 순서는 다음과 같다.

  • /etc/my.cnf 
  • /etc/mysql/my.cnf 
  • /usr/local/mysql/etc/my.cnf 
  • ~/.my.cnf
일단 /etc/my.cnf파일이 있는지 확인후 없으면 /usr/local/mysql/support-files 폴더에서 my-default.cnf파일을 복사해온다.

EminentStarui-MacBook-Pro:support-files eminentstar$ sudo cp /usr/local/Cellar/mysql/5.6.25/support-files/my-default.cnf /etc/my.cnf


그리고 /etc/my.cnf파일에 다음 내용을 추가한다.

[mysqld]

character-set-server=utf8

collation-server=utf8_general_ci


init_connect=SET collation_connection=utf8_general_ci

init_connect=SET NAMES utf8


[client]

default-character-set=utf8


[mysql]

default-character-set=utf8


이제 서버 재시작. sudo 권한이 없으면 sudo를 붙인다.

EminentStarui-MacBook-Pro:etc eminentstar$ /usr/local/Cellar/mysql/5.6.25/support-files/mysql.server restart


*DB 생성 및 생성된 DB 사용자 추가하기

mysql> create database testdb;

Query OK, 1 row affected (0.00 sec)


mysql> show create database testdb;

+----------+-----------------------------------------------------------------+

| Database | Create Database                                                 |

+----------+-----------------------------------------------------------------+

| testdb   | CREATE DATABASE `testdb` /*!40100 DEFAULT CHARACTER SET utf8 */ |

+----------+-----------------------------------------------------------------+

1 row in set (0.00 sec)


이제 권한 추가하기.
-grant 명령어 이용

mysql> grant all privileges on testdb.* to dev@localhost identified by '0000';

Query OK, 0 rows affected (0.00 sec)


(dev라는 계정을 만들고 이 계정으로 사용할 testdb도 지정. 이제 root가 아닌 dev계정으로 로그인 해서 사용할수있는 DB가 보이는지 확인하자.)

EminentStarui-MacBook-Pro:etc eminentstar$ mysql -u dev -p

Warning: World-writable config file '/etc/my.cnf' is ignored

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| test               |

| testdb             |

+--------------------+

3 rows in set (0.00 sec)


mysql> 


testdb도 보인다. 여기까지가 mysql로 개발할때 필요한 기본 과정이다.




'Database > Mysql' 카테고리의 다른 글

MySQL 테이블 생성하기  (0) 2015.07.14
MySQL 설치하기(2015.07.11)  (0) 2015.07.11
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함