Global It Leader!!



 
 

Mysql 자주 사용하는 명령어 정리

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 5,297회 작성일 12-02-21 00:02

본문

■ Mysql 데몬 start 하기
# /usr/local/mysql/bin/mysqld_safe &
또는  # /usr/local/mysql/share/mysql/mysql.server start

■ Mysql 데몬 stop 하기
# /usr/local/mysql/bin/mysqladmin -uroot shutdown
또는   # /usr/local/mysql/share/mysql/mysql.server stop

■ Mysql 접속 방법

형식 : mysql -u 사용자 -p 사용DB
예제)    # /usr/local/mysql/bin/mysql -u root -p mysql
           Enter password:      -> 초기 세팅후 비밀번호가 지정되지 않은경우는 엔터

또는

           # /usr/local/mysql/bin/mysql mysql -p
           Enter password:

■ mysql의 root암호설정법
  mysql> update user SET Password=password('비밀번호') where user='root';

■ 일반계정의 비밀번호 변경시
  mysql> update user set password=password('새비밀번호') where user='계정명';

■ DB 생성명령
  mysql> create database DB명
  

■ DB 사용자 계정 생성 방법(각 버전 별 필드 수를 확인 하시어 이용하시면 됩니다.)

◊ mysql 3.xx 에서 생성방법
  mysql> insert into user values('localhost','계정명',password('비밀번 호'),'N',
        'N','N','N','N','N','N','N','N','N','N','N','N','N');

  mysql> insert into db values('localhost','DB명','계정명','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

  mysql> FLUSH PRIVILEGES;     (새로 만든 디비를 MYSQL에 적용하기 위하여 reload함)

◊ mysql 4.0.xx 에서 생성방법
  mysql> insert into db values ('localhost','DB명','DB계정명','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');


mysql> insert into user (host, user, password) values ('localhost','DB계정명',password('비밀번호'));
또는 아래와 같이도 생성가능함
  mysql> INSERT INTO user VALUES ('localhost','DB계정명',password('비밀번호'),
'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0);

  mysql> FLUSH PRIVILEGES;

◊ mysql 4.1.xx 에서 생성방법
  mysql> insert into user (host, user, password) values ('localhost','DB계정명',password('비밀번호'));

  mysql> INSERT INTO db(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv)
VALUES('localhost','DB명','DB계정명','Y','Y','Y','Y','Y','Y');

  mysql> FLUSH PRIVILEGES;

● GRANT 로 생성하는 방법
  mysql> GRANT ALL PRIVILEGES ON DB명.* TO DB계정명@localhost IDENTIFIED BY '비밀번호' WITH GRANT OPTION;
=> localhost에서 'DB계정명' 이라는 사용자를 등록시

  mysql> GRANT ALL PRIVILEGES ON DB명.* TO DB계정명@'%' IDENTIFIED BY '비밀번호' WITH GRANT OPTION;
=> localhost 아닌 원격에서 접속시 호스트 부분을 % 로 해준다.


■ 계정,DB 생성 확인
  mysql> select * from user;


■ 기타 mysql에서 자주 사용되는 명령들

▷ DB삭제시
  mysql> drop database DB명

▷ DB 계정 삭제시
  mysql> delete from user where user='DBuser';  => (DBuser 라는 user 레코드를 삭제시)
  mysql> delete from db where user='DB';  => (DB 라는 db 레코드를 삭제시)
  mysql> FLUSH PRIVILEGES;

▷ DB선택시
  mysql> use DB명;

▷ DB 및 테이블 list보기
  mysql> show databases;
  mysql> show tables;

▷ mysql상의 테이블 정보 보기
  mysql> show tables from mysql;

▷ DB table의 칼럼정보 보기
  mysql> show columns from db;

▷ 테이블구조
  mysql> describe 테이블명;

▷ 인덱스 보기
  mysql> show index from 테이블명;

▷ 버전체크
  mysql> select version();

▷ MySQL의 상태 보기
  mysql> show status;

▷ MySQL 환경변수보기
  mysql> show variables;


◆ mysql 백업 하기
  # /usr/local/mysql/bin/mysqldump {-h 호스트} -u 사용자 -p DB명 > 백업파일명.sql

◆ mysql 복구 하기
  # /usr/local/mysql/bin/mysql {-h 호스트} -u 사용자 -p DB명 < 백업파일명.sql

  => {-h 호스트}는 원격접속시나 호스트명이 별도로 분류되어 있는경우에 사용
  

◆ Mysql root 비밀번호를 분실한 경우 조치방법

1. 실행중인 msyql 종료
  # killall mysqld  또는 killall -9 mysqld
  # ps -ef | grep mysqld  (mysql 데몬 없음을 확인)

2. grant-table 미사용모드로 mysql시작
  (mysql 3.x 사용시)
  # /usr/local/mysql/bin/safe_mysqld  --skip-grant-tables &
  (mysql 4.x 에서 사용시)
  # /usr/local/mysql/bin/mysqld_safe  --skip-grant-tables &
  # /usr/local/mysql/bin/mysql -u root -p mysql

3. update문으로 root사용자 패스워드 설정
  mysql> update user set password=password('newpasswd') where user = 'root';
  mysql> flush privileges;

4. 실행중인 mysql 다시 종료
  # killall mysqld  또는 killall -9 mysqld
  # ps -ef | grep mysqld  (mysql 데몬 없음을 확인)

5. Mysql 데몬 다시 시작
  # /usr/local/mysql/bin/safe_mysqld &
  # ps -ef | grep mysql
  # /usr/local/mysql/bin/mysql -u root -p mysql
    Enter Password:

댓글목록

등록된 댓글이 없습니다.

전체 440
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
100 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5796 02-29
99 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5862 02-29
98 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5104 02-29
97 HTML no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5486 02-29
96 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5328 02-29
95 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7168 02-29
94 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6199 02-28
93 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6043 02-28
92 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4963 02-28
91 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5275 02-27
90 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5805 02-27
89 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5990 02-27
88 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5536 02-22
87 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5063 02-26
열람중 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5298 02-21
85 CSS no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5184 02-17
84 CSS no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5177 02-17
83 HTML no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5515 02-17
82 CSS no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5001 02-17
81 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5342 02-14