본문 바로가기
Server/Ubuntu

우분투에서 mysql 접근 및 사용

by 유주원 2013. 8. 7.

mysql 설치

>> sudo apt-get install libapache2-mod-auth-mysql

>> sudo apt-get install mysql-server mysql-client


mysql 로그인

>> mysql -u 사용자명 -p


root 암호 변경

>> mysqladmin -u root -p password "새 비밀번호"


데이터베이스 생성

mysql> create database db명;


데이터베이스 삭제

mysql> drop database db명;


사용자 생성하기

mysql> CREATE USER 아이디@localhost IDENTIFIED BY '비밀번호';


사용자 목록 확인

mysql> use mysql;

mysql> select user, host from user;


사용자에게 DB 권한 부여

mysql> GRANT ALL PRIVILEGES ON db명.* TO 아이디@localhost;

or

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON db명.* TO 아이디@localhost;


사용자 권한 확인

mysql> SHOW GRANTS FOR 아이디@localhost;


사용자 권한 제거

mysql> REVOKE ALL PRIVILEGES ON db명.* FROM 아이디@localhost;


사용자 삭제

mysql> DROP USER 아이디@localhost;


데이터 베이스의 용량 확인

mysql> SELECT table_schema "Database Name", SUN(data_length + index_length) / 1024 / 1024 "Size(MB)" FROM 

information_schema.TABLES GROUP BY table_schema;


테이블 생성하기

mysql> CREATE TABLE table1(

id int(11) not null auto_increment primary key,

last_date datetime not null,

name varchar(10));


데이터 삽입하기

mysql> INSERT INTO table1 (last_date, name) values('20130807', '테스트');


데이터 삭제하기

mysql> DELETE FROM table1 where id = '1'; 


데이터 수정하기

mysql> UPDATE table1 SET last_date='20130808', name='test2' where id = '1';