꼬반 Blog

MySQL 설치하기

====== Mysql ======
===== 보안 설정 =====
http://qiita.com/TatsuNet/items/f284d3ba0ac71def2a63 << 추천
http://www.iblue.kr/xe/index.php?document_srl=35923&mid=board_kiyj73

===== Root Password 설정 =====

mysql을 설치 후 처음 접속할때는 root에 password 가 설정 되어 있지 않다.

  $ /usr/bin/mysqladmin -u root -p password 'new-password'

'new-password' 에 사용할 패스워드를 입력하면 된다.

===== Root 원격 접속 설정 =====
 
  mysql> grant all privileges on *.* to 'root'@'%' identified by 'root의 패스워드';
  mysql> flush privileges;

mysql에서 명령어들은 대소문자 구문없이 사용이 가능하나 테이블의 값들은 대소문자를 구별하니 잘 사용하자.

all privileges 는 모든 권한을 의미한다.
grant select, update, insert on ... 과 같이 구분하여 권한 설정이 가능 하다.

*.* : 모든 DB에 대해 모든 테이블을 의미
db명.* : 특정 db에 대한 모든 테이블
db명.권한 : 특정 db에 대한 특정 테이블

'root'@'%' : root계정에 대해 모든 host 접속 허용
'root'@'localhost' : root계정에 대해 localhost 에서의 접속만 허용
'root'@'ip' : root계정에 대해 특정 ip 접속만 허용
'root'@'xxx.xxx.xxx.xxx' : root계정에 대해 특정 ip 대역 허용
  root 계정을 user id로 사용하면 해당 user에 대해 접속 권한을 설정할 수 있다.

===== mysql 접속자수 확인 =====

출처 : http://www.ssongacademy.com/index.php?document_srl=563&mid=linux_mysql

too many connections 를 확인한다면
myslq 접속자수 또한 확인하고 설정을 해야한다.

<code>
[root@localhost logrotate.d]# mysqladmin -u root -p proc stat
Enter password:
+------+------+-----------+----+---------+------+-------+------------------+
| Id   | User | Host      | db | Command | Time | State | Info             |
+------+------+-----------+----+---------+------+-------+------------------+
| 7996 | root | localhost |    | Query   | 0    |       | show processlist |
+------+------+-----------+----+---------+------+-------+------------------+
Uptime: 432759  Threads: 1  Questions: 315099  Slow queries: 0  Opens: 4783  Flush tables: 1  Open tables: 64  Queries per second avg: 0.728
 
Uptime : the MySQL server 시작된 후 현재까지 시간 (초)
Threads : 현재 디비서버에 연결된 유저수
Questions : 서버시작후 지금까지 요청된 쿼리수
Slow queries : --log-slow-queries[=file_name] option로 시작된 서버가 variables에 지정된
long_query_time seconds시간보다 큰 쿼리시간을 가진 요청수
Opens : 서버가 시작된 후 현재까지 열렸던 테이블 수
Flush tables : flush ..., refresh, and reload commands된 수
Open tables : 현재 열려 있는 테이블 수
Queries per second avg : 평균 초당 쿼리수
 
Memory in use :the mysqld code에 의해 직접 할당된 메모리 (only available when MySQL is compiled with --with-debug=full).
Max memory used : the mysqld code에 의해 직접 할당된 최대메모리 (only available when MySQL is compiled with --with-debug=full).
</code>

===== [mysql] mysql 비밀번호 초기화 =====

테스트를 진행하다보면 mysql 비밀번호를 초기화 할 때가 있습니다.

비밀번호를 업데이트 할 경우,
간혹 다음과 같은 에러메시지를 보기도 합니다.

  ERROR 1142 (42000): UPDATE command denied to user ''@'localhost' for table 'user'

  ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
 
이럴 경우 비밀번호를 초기화하는 방법은...

1. mysqld_safe --skip-grant-tables &

2. mysql -u root -p

[엔터]

3. update mysql.user set password=password('변경 비밀번호') where user='root';

4. flush privileges;

입니다...

비밀번호 변경 후,

mysql -u root -p 명령을 내리면

변경된 비밀번호를 넣어야 접근이 가능하게 됩니다.

참고자료 :  http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-unix

===== 한글 셋 변경 =====

http://tedwon.com/pages/viewpage.action?pageId=30244996

===== mysql.socket error =====

설치 후 설정파일을 변경하는 경우 해당 문제가 발생하는 경우가 많다.

보통 이런경우 실제 sock 파일을 에러에 나오는 경로에 링크를 생성하여 주는데 이보다는

설정파일에

<code>
[client]
socket=소켓위치
</code>

로 설정하여 주면 된다.


반응형

Article By 꼬반

*certificate* : VCP 5(2012), RHCSA 7 (2014), RHCE 7 (2015), RHCSA in REDHAT OpenStack(2017) *development language* : Javascript, NodeJS, Golang, html5, css3, shell script *middle ware* : NGINX, Apache, Tomcat, Docker, Docker Swarm, Mesos, Kubernetes, HCI,

Discuss about post