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
번호 분류 제목 날짜 조회 수
897 컴퓨터잡담 H734GP 공유기 시스템로그 중 >>> Send Offer / Receive Discover / 2023.06.04 51471
896 WindowsTip VBS) FTP.scriptlet and Shell.scriptlet 2013.09.21 48506
895 파이썬 python AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector' 해결방법 2023.05.07 47487
894 AutoHotKey AHK) 보안프로그램 등으로 화면복사(Printscreen) 안될때 사용방법 1 12 file 2012.11.21 47165
893 프로세스 pinomate.exe 프로세스 삭제방법 6 2011.02.13 45998
892 WindowsTip VBS) PostMessage or SendMessage to external program 2013.09.21 45965
891 컴퓨터잡담 [PHP] 원격지의 이미지 사이즈 구하는 방법 2 2009.08.11 44528
890 AutoHotKey Ahk) 웹페이지 감시결과에 따라 마이피플로 글 전송하기 12 file 2013.01.06 44022
889 컴퓨터잡담 emule 서버리스트 2010.11.10 43048
888 Excel Excel Vba) 셀의 행, 열(column, row) 주소 알아내기 또는 삽입하기 더불어 제어하기 2012.01.05 42974
887 컴퓨터잡담 2023-09-23 서버다운 후 복구완료 secret 2023.09.23 42370
886 AutoHotKey Autohotkey) 화면보호기(ScreenSaver) On/Off 방법 17 2012.03.16 40675
885 [Docs]스프레드시트 구글 스프레드시트에서 셀값이 특정일에서 현재일과 3일 이내의 범위에 들어오면 이메일을 발송하는 방법 2023.03.26 40466
884 Excel GET.CELL 매크로함수 응용 11 2012.07.16 40175
883 컴퓨터잡담 안드로이드 동영상 재생시 파란색 물음표 박스만 나올때 조치방법 2 file 2013.04.26 39285
882 컴퓨터잡담 URL Encoding 특수문자코드 4 2012.03.30 39034
881 컴퓨터잡담 mysql 날짜타입에 기본값으로 현재시간넣기 1 2009.12.07 38588
880 AutoHotKey ahk) 오토핫키 콤보박스 제어하기 file 2013.10.30 38176
879 WindowsTip 네트워크에 있는 다른 시스템과 ip 주소가 충돌합니다. 1 file 2013.03.29 38112
878 컴퓨터잡담 테블릿을 세컨트모니터로??? 2023.04.26 38037
Board Pagination Prev 1 2 3 4 5 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소