Skip to content
컴퓨터잡담
2009.11.19 08:35

mysql 재시작, 사용자 추가 명령어

조회 수 32229 추천 수 0 댓글 1
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

mysql 재시작, 사용자 추가 명령어


mysql 재시작 명령어


MYSQL 종료 명령어 
#mysqladmin -u root -p shutdown 한다음에 
#mysql-dir/bin/safe_mysqld 
  
 MYSQL 재시작 명령어 
#mysql-dir/bin/safe_mysqld & 


굳이 mysql 종료 후 재시작을 기본으로 하는 이유는 db 재시작시에 쿼리전송이 일어날 수 있어

기록 못하는 일을 방지하고자 종료 후 다시시작하는 것을 원칙으로 합니다.



MySQL 초기화 스크립트(http://gooranet.tistory.com/79)


1. Test Table 데이터 및 Account 삭제, root 패스워드 변경

DROP DATABASE IF EXISTS test;
USE mysql;
DELETE FROM db WHERE db LIKE 'test%';
DELETE FROM user WHERE host = '%';
DELETE FROM user WHERE User = '';
UPDATE user SET Password = PASSWORD('패스워드'WHERE User = 'root';
FLUSH PRIVILEGES;


2. Database, User(select 전용, insert/update/delete 전용) 추가

CREATE DATABASE 디비명;
GRANT select ON 디비명.* TO 셀렉트용아이디@"호트스명" IDENTIFIED BY "패스워드"
;
GRANT insert,update,delete ON 디비명.* TO 업데이트/인서트용아이디@"호스트명" IDENTIFIED BY "패스워드"
;
FLUSH PRIVILEGES;


3. Schema 수정 using ALTER

ALTER TABLE 테이블명 ADD 추가할 내용(컬럼, 키, 인덱스 등)
Ex) ALTER TABLE table1 ADD column1 CHAR(5) AFTER column2
;

ALTER TABLE 테이블명 MODIFY 수정할 내용;
Ex1) ALTER TABLE table1 MODIFY (column1 INT(8) NULL);
Ex2) ALTER TABLE table1 RENAME AS table2;
Ex3) ALTER TABLE table2 CHANGE old old TINYINT NOT NULL, CHANGE old new CHAR(20);

ALTER TABLE 테이블명 DROP PRIMARYKEY;
ALTER TABLE 테이블명 DROP COLUMN 지울 컬럼명;




mysql autoincrement초기화 방법
alter table 테이블명 auto_increment = 1



MySQL 접속
$ mysql -u root -p

root 암호 초기화
mysql> UPDATE user SET password=password('new_password'WHERE user='root';
mysql> FLUSH privileges;


데이터베이스 선택 및 보기
mysql> USE mysql;
mysql> SELECT Host, User, Password FROM user;


사용자 추가
- 서버 주소의 경우 localhost, %, 127.0.0.1 도 같이 처리해 줍니다. 
- 외부 접속은 'localhost'  대신에 '%' 를 사용합니다. 

mysql> INSERT INTO user (Host, User, Password) VALUES ('localhost''유저명', password('유저패스워드'));
mysql> INSERT INTO user (Host, User, Password) VALUES ('127.0.0.1''유저명', password('유저패스워드'));
mysql> INSERT INTO user (Host, User, Password) VALUES ('%''유저명', password('유저패스워드'));
mysql> FLUSH privileges;


사용자 삭제 예
mysql> DELETE FROM user WHERE user='root'  and host='%';


데이터베이스 추가 및 권한 주기
- 모든 권한시 데이터베이스명.* 대신 *.* 로 처리합니다. 

mysql> CREATE DATABASE 데이터베이스명;
mysql> GRANT ALL privileges ON 데이터베이스명.* TO 유저명@localhost IDENTIFIED BY '유저패스워드';
mysql> GRANT ALL privileges ON 데이터베이스명.* TO 유저명@127.0.0.1 IDENTIFIED BY '유저패스워드';
mysql> GRANT ALL privileges ON 데이터베이스명.* TO 유저명@'%' IDENTIFIED BY '유저패스워드';


이렇게 해서 외부접속이 안되면 insert into 구문 잘못 입력시 % 가 잘못 입력되거나 패스워드를 유저 패스워드가 아닌 root 패스워드를 입력했을 가능성이 있습니다. 이 경우 % 를 다시 바꿔주면 됩니다.

mysql> UPDATE INTO user SET Host='%' WHERE user='유저명';
mysql> FLUSH privileges;

로그인 후 댓글쓰기가 가능합니다.

?
  • ?
    디케 2009.11.19 08:47

    http://spaceufo.wordpress.com/category/mysql/mysqladmin/

    • mysqladmin -u root -p proc stat(=processlist) –> 서버에 현재 활동중인 threads상태보기
    • mysqladmin status

      • 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).
    • mysqladmin -u root -p ping –>디비서버가 살아있는지 확인
    • mysqladmin -u root -p extended-status(※mysql>show stauts)
    • mysqladmin -u root -p variables(※mysql>show valiables)
    • mysqladmin create [databasename] : Create a new database.
    • mysqladmin drop [databasename] : Delete a database and all its tables.
    • mysqladmin flush-hosts : Flush all cached hosts.
    • mysqladmin flush-logs : Flush all logs.
    • mysqladmin flush-tables : Flush all tables.
    • mysqladmin flush-privileges : Reload grant tables (same as reload).
    • mysqladmin kill [id(,id,...)] : Kill mysql threads.
    • mysqladmin password : Set a new password. Change old password to new-password.
    • mysqladmin reload : Reload grant tables.
    • mysqladmin refresh : Flush all tables and close and open logfiles.
    • mysqladmin shutdown : Take server down.
    • mysqladmin slave-start : Start slave replication thread.
    • mysqladmin slave-stop : Stop slave replication thread.
    • mysqladmin version : Get version info from server.


List of Articles
번호 분류 제목 날짜 조회 수
677 컴퓨터잡담 Mysql 에러메시지 2010.04.27 17549
» 컴퓨터잡담 mysql 재시작, 사용자 추가 명령어 1 2 2009.11.19 32229
675 컴퓨터잡담 mysql 접속불가시 재부팅 2009.11.24 12088
674 컴퓨터잡담 mysql 접속에러시 재부팅 하는 배치파일 2009.11.24 26693
673 컴퓨터잡담 MySQL 조율(튜닝)에 대해 2 2010.04.14 15804
672 컴퓨터잡담 MYSQL 최적화 2 2009.11.13 22447
671 Server mysql 테이블 손상시 #1146 - Table 해결방법 file 2016.07.17 8905
670 Server MYSQL 튜닝 이정도는 해야되지 않겠나? 2 file 2012.07.16 7991
669 컴퓨터잡담 Mysql) mysql mysql-bin.0000x 로그 기록설정방법(사용안함설정등) 2 2012.01.23 7843
668 컴퓨터잡담 mysqladmin 3 2009.11.19 14065
667 AutoHotKey Mysqld 프로세서 실시간 감시 2011.02.06 7611
666 HTMLPHPMSQL mysqli로 DB 검색 조회 2017.11.08 6900
665 컴퓨터잡담 MySQL을 위한 하드웨어 최적화(What one can and should optimize) 2 2010.04.06 13123
664 프로세스 npkcmsvc.exe 서비스 끄기 (엔프로텍트 nProtect) 1 3 2011.02.06 13324
663 컴퓨터잡담 nVIDIA GTX750Ti 드라이버 file 2019.02.19 6821
662 프로세스 NVSvc.exe 프로세스 삭제방법 1 2011.02.13 21652
661 AutoHotKey OnMessage() 3 2011.02.05 20463
660 컴퓨터잡담 PC를 자동으로 부팅시작 1 file 2021.10.10 4098
659 컴퓨터잡담 PC에 안드로이드 설치하기 2015.12.01 989
658 컴퓨터잡담 PC에 안드로이드 설치하기 1 file 2015.07.18 5442
Board Pagination Prev 1 ... 11 12 13 14 15 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소