mysql –u root -p
create database DBNAME
grant all privileges on DBNAME.* to USERNAME@'%' identified by 'PASSWORD’;
flush privileges;
mysql –h 127.0.0.1 –u USERNAME –p DBNAME
exit;
SELECT VERSION(), CURRENT_DATE;
use DBNAME;
mysql -u USERNAME -p DBNAME < FILE.sql
mysql -u USERNAME -p DBNAME
show tables;
desc bonus;
SELECT
select empno, job from employee;
select empno 사번, job 직무 from employee;
select distinct depno from employee;
select empno, name from employee order by empno;
select empno, name from employee order by empno desc;
select empno, name from employee order by 2;
select concat(empno, '-', name) as '사번-이름' from employee;
select * from employee where empno = 7934;
select * from employee where job = 'MANAGER';
select * from employee where deptno in (10,30);
select * from employee where deptno = 10 and salary < 1500;
select name, job from employee where name like 'A%';
select name, job from employee where name like '_A%';
select lower(name) from employee;
select substring(name, 1, 2) from employee;
select LPAD(name, 10, '*') from employee;
select RPAD(name, 10, '*') from employee;
select trim(name) from employee;
select cast(now() as date);
select count(comm) from employee;
select deptno, avg(salary) from employee group by deptno;
INSERT, UPDATE, DELETE
insert into role (role_id, role_name) values (200, 'CEO');
insert into role values (200, 'CEO');
update role set role_id = 104 where role_name = 'CEO';
delete from role where role_id = 104;
테이블
create schedule(
subjct varchar(20) not null primary key,
time varchar(30) not null,
hours tinyint not null,
professor varchar(20),
credit tinyint default 3
);
alter table schedule add exam_date varchar(10);
alter table schedule drop exam_date;
alter table schedule change subjct subject varchar(50);
alter table schedule change hours hours tinyint null;
alter table schedule rename school_schedule;
drop table school_schedule;
데이터 타입