프로그램/database

Mysql 디비 만들기, 유저만들어 권한할당해주기, SQL 임포트

mulderu 2012. 4. 22. 13:17

Mysql DB Create, User Create, Grant Access, SQL Import


Mysql  데이터베이스의 시작 : user 및 database 만들기 


1. Mysql UTF-8  문자셋으로 Database  만들기.

   CREATE DATABASE your-database-name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

2. Mysql  User를 만들고 database 접속권한 부여

  grant all privileges on your-database-name.* to 'userid'@'localhost' identified by 'pwd' with grant option;

3. SQL database Import

  mysql -uroot your-database-name < import-your-db.dump.sql


mulder@~/temp/work/dbdata$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.1.44 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> mysql> CREATE DATABASE mallv5 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.00 sec) mysql> grant all privileges on mallv5.* to 'userid'@'localhost' identified by 'pwd' with grant option; Query OK, 0 rows affected (0.03 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> mysql> exit Bye mulder@~/temp/work/dbdata$ mysql -uroot mallv5 < mallv5.dump.sql mulder@~/temp/work/dbdata$



[ case by case 계정 만들기 ] 


select  만 가능한 계정 만들기

GRANT SELECT ON db_base.* TO db_user@'localhost' IDENTIFIED BY 'db_passwd';


select, insert, delete 권한을 주면 유저 생성하기

GRANT SELECT, INSERT, DELETE ON db_base.* TO db_user@'localhost' IDENTIFIED BY 'db_passwd';


GRANT ALL :  모든권한을 다 준다.

GRANT ALL PRIVILEGES ON db_base.* TO db_user @'%' IDENTIFIED BY 'db_passwd';

As you see in the latest example we use '%' instead of localhost, which means that our user can use all the privileges from every host.