생활코딩

Coding Everybody

코스 전체목록

닫기

데이터베이스(MySQL) 이론

데이터베이스 이론1

codeanywhere를 실습환경으로 이용하고 계신 분들은 codeanywhere로 터미널 이용하기 영상을 보시면 다음 영상의 실습을 따라할 수 있습니다.

데이터베이스 이론2

윈도우 

mysql -hlocalhost -uroot -p

리눅스, 맥

./mysql -hlocalhost -uroot -p

데이터베이스 보기

show databases;

데이터베이스 생성

CREATE DATABASE opentutorials CHARACTER SET utf8 COLLATE utf8_general_ci;

데이터베이스 선택

use opentutorials;

테이블 생성

CREATE TABLE `topic` (
`id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(100) NOT NULL,
  `description` text NOT NULL,
  `author` varchar(30) NOT NULL,
  `created` datetime NOT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

생성된 테이블 확인

show tables;

데이터 삽입

INSERT INTO `topic` (`id`, `title`, `description`, `author`, `created`) VALUES(1, 'About JavaScript', '<h3>Desctiption</h3>\r\n<p>JavaScript  is a dynamic computer programming language. It is most commonly used as part of web browsers, whose implementations allow client-side scripts to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed.</p>\r\n<p>\r\nDespite some naming, syntactic, and standard library similarities, JavaScript and Java are otherwise unrelated and have very different semantics. The syntax of JavaScript is actually derived from C, while the semantics and design are influenced by the Self and Scheme programming languages.\r\n</p>\r\n<h3>See Also</h3>\r\n<ul>\r\n  <li><a href="http://en.wikipedia.org/wiki/Dynamic_HTML">Dynamic HTML and Ajax (programming)</a></li>\r\n  <li><a href="http://en.wikipedia.org/wiki/Web_interoperability">Web interoperability</a></li>\r\n  <li><a href="http://en.wikipedia.org/wiki/Web_accessibility">Web accessibility</a></li>\r\n</ul>\r\n', 'egoing', '2015-03-31 12:14:00');
INSERT INTO `topic` (`id`, `title`, `description`, `author`, `created`) VALUES(2, 'Variable and Constant', '<h3>Desciption</h3>\r\n\r\nIn computer programming, a variable or scalar is a storage location paired with an associated symbolic name (an identifier), which contains some known or unknown quantity or information referred to as a value. The variable name is the usual way to reference the stored value; this separation of name and content allows the name to be used independently of the exact information it represents. The identifier in computer source code can be bound to a value during run time, and the value of the variable may thus change during the course of program execution.\r\n\r\n<h3>See Also</h3>\r\n<ul>\r\n<li>Non-local variable</li>\r\n<li>Variable interpolation</li>\r\n</ul>\r\n', 'k8805', '2015-05-14 10:04:00');
INSERT INTO `topic` (`id`, `title`, `description`, `author`, `created`) VALUES(3, 'Opeartor', '<h2>Operator</h2>\r\n<h3>Description</h3>\r\n<p>Programming languages typically support a set of operators: constructs which behave generally like functions, but which differ syntactically or semantically from usual functions</p>\r\n<p>Common simple examples include arithmetic (addition with +, comparison with >) and logical operations (such as AND or &&). </p>\r\n', 'egoing', '2015-06-18 05:00:00');
INSERT INTO `topic` (`id`, `title`, `description`, `author`, `created`) VALUES(4, 'Conditional', '<h3>Description</h3>\r\n<p>In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. Apart from the case of branch predication, this is always achieved by selectively altering the control flow based on some condition.</p>\r\n<p>In imperative programming languages, the term "conditional statement" is usually used, whereas in functional programming, the terms "conditional expression" or "conditional construct" are preferred, because these terms all have distinct meanings.</p>\r\n<h3>See Also</h3>\r\n<ul>\r\n<li><a href="http://en.wikipedia.org/wiki/Branch_(computer_science)" title="Branch (computer science)">Branch (computer science)</a></li>\r\n<li><a href="http://en.wikipedia.org/wiki/Conditional_compilation" title="Conditional compilation">Conditional compilation</a></li>\r\n<li><a href="http://en.wikipedia.org/wiki/Dynamic_dispatch" title="Dynamic dispatch">Dynamic dispatch</a> for another way to make execution choices</li>\r\n<li><a href="http://en.wikipedia.org/wiki/McCarthy_Formalism" title="McCarthy Formalism">McCarthy Formalism</a> for history and historical references</li>\r\n<li><a href="http://en.wikipedia.org/wiki/Named_condition" title="Named condition" class="mw-redirect">Named condition</a></li>\r\n<li><a href="http://en.wikipedia.org/wiki/Test_(Unix)" title="Test (Unix)">Test (Unix)</a></li>\r\n<li><a href="http://en.wikipedia.org/wiki/Yoda_conditions" title="Yoda conditions">Yoda conditions</a></li>\r\n</ul>', 'c2', '2015-07-25 00:00:00');

 

댓글

댓글 본문
  1. 터병
    22.4.4. 감사합니다.
  2. 박상현
    감사합니다 언제나 잘보고 있습니다
  3. Ella
    *비밀번호 분실한 경우* (mysql 10.4.20.0 기준, 속성에서 자세히 탭 가시면 볼 수 있습니다.)


    1. C드라이브 > Bitnami > wampstack-8.0.8-0(버전마다 다름) > manager-windows 실행, Manage Servers 탭에서 MariaDB(mysql) Database를 Stop 시킵니다.

    2. 강의에서 나온대로 C드라이브 > Bitnami > wampstack-8.0.8-0(버전마다 다름) > marisdb(혹은 mysql : 이전 강의에서 MariaDB랑 mysql은 거의 같다고 하셨었죠!) > bin > mysql(응용프로그램)을 우클릭하여 속성에 들어간 뒤 위치 주소를 복사합니다.

    3. 강의에서 나온대로 cmd창을 열어 cd (2에서 복사한 주소) 를 입력하고 엔터

    4. mysqld --skip-grant-tables --user=root & 을 입력한 후 엔터

    5. 4까지 이용하던 cmd창은 그대로 두고 새로운 cmd창을 엽니다.

    6. 3에서와 똑같이 cd (2에서 복사한 주소) 를 입력하고 엔터

    7. mysql 입력하고 엔터 (Welcome to~ 나옵니다.)

    8. flush privileges; 입력하고 엔터 (Query OK, ~ 나옵니다.)

    9. alter user 'root'@'localhost' identified by '(바꿀 비밀번호)'; 입력하고 엔터 (Query OK, ~ 나옵니다.)

    10. quit 입력하고 엔터 (Bye 나옵니다.)

    11. 10까지 오류 없이 완료되었다면 cmd창을 모두 끄고 다시 처음부터 강의와 똑같이 진행하면 방금 바꾼 패스워드로 인증할 수 있습니다.
    (새로운 cmd창을 열어 다시 cd (2에서 복사한 주소) 를 입력하고 엔터 > mysql -hlocalhost -uroot -p 입력한 후 엔터 > Welcome to~ 나옵니다.)


    혹시 도움이 될지 몰라 올려봅니다. 전 이거때문에 2시간 넘게 헤맸네요... 요새 버전(10.4 이후)은 예전 버전과 변경하는 방법이 다르고, 저는 잘 모르지만 변경하는 방법도 여러가지인 것 같고 그래서 이것저것 시도해보고 실패하다가 결국 이 방법으로 아주 간단하게 변경할 수 있었습니다. 진이 다 빠집니다 ㅜㅜ 많이 헤메기 전에 이 글을 보셨길..
  4. 홍영환
    SELECT * FROM topic;
    넣은데이터를 가져오기
  5. Seonggyeong Jeon
    사람님 mariadb>bin>보시면 mysql 있어요! 혹시나하고 들어가봤더니 있네요!! 정상작동합니당
    대화보기
    • Seonggyeong Jeon
      저두요 ㅠㅠ 비번 까먹어서 재설치 헀더니 mysql 이 아예 없어져버렸네요 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ
      대화보기
      • 사람
        저는 비번 까먹어서
        삭제 후 다시 깔았는데
        myspl 파일은 없고,
        서버 목록에는 MariaDB Database라는 것 만 있네요...
        현재는 파일 같은 것 다 망한상태....
        ㅠㅠ
      • 기리보이
        혹시 몰라서 댓글 남겨요
        mac 유저중에서
        cd /Applications/mampstack-8.0.7-1/mysql/bin 에서
        mysql 대신 mariadb 입력하고
        ./mysql -hlocalhost -uroot -p
        이렇게 입력하고 비번 치면 되네요
        제가 딴 것을 설치한 건지 시간이 많이 지나서 바뀐 건지 몰라도
        안 되시는 분들 한번 해보세요!
      • heyri
        210615 다시 정리 필요
      • James Hanjoo Park
        감사합니다. 수고하셨습니다.
      • coding_prince
        감사합니다.
      • 시리구
        데이터를 삽입했을 때 명령프롬프트창에
        ERROR 2005 (HY000) : Unknown MySQL server host 'is'(2)랑 같이 서버를 찾을 수 없다는 오류가 뜨는데
        해결방법이 있을까요? 도저히 해결방법을 찾을 수 가 없네요 ㅜㅜㅜ

        ----------------------------------------------------------------------------------------------------------------------------프로123
        프로그램을 껐다가 키니까 되긴하는ㄷ데 에러가 뜨는 이유 좀 알려주세요!!
      • 박상현
        몇몇분들이 저랑 비슷한 문제를 겪고 계신것 같아 올려봅니다.

        운영체제: Ubuntu 20.10 LTS

        ./mysql.bin: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

        위와 같은 오류가 나오는 경우가 있는데 이런 경우는 최신 버전의 우분투에 특정 'shared library' 가 설치되어 있지 않아서 그런것 같습니다.

        Bitnami 공식 troubleshooting 사이트에 들어가 보시면 아래의 명령어를 넣어 libtinfo.so.5를 설치하라고 합니다

        sudo apt-get install libncurses5

        sudo 커맨드를 무조건 사용하셔야 하며 비밀번호 입력 요청이 나올겁니다. 약 180kb 정도의 파일을 다운로드하게 되고 입력해 보니 정상작동 하는것 같군요. 한번 시도해 보시기 바랍니다.

        만일 설치가 안되거나 하시면

        sudo apt-get update
        sudo apt-get upgrade

        로 응용프로그램 전체 업데이트 후 시도해 보세요. 저도 잘 모르지만 어찌저찌하다 찾아 공유해 봅니다. 혹시 틀린점 있으면 지적해주세요 =)

        아래는 bitnami 공식 troubleshooting 웹사이트입니다.
        https://docs.bitnami.com......ts/
      • 정착유목민
        MSSQL을 조금 알고 있어 쉽게 될 줄 알았다. 그런데, UI가 없는 명령어 창이라니 ..... 쉽지가 않네요.
      • 정착유목민
        drop table 하시고, 다시 Create하시면 될것 같네요.
        대화보기
        • 한번가보자
          가보자
        • 늦은나이가아님
          2020.12.14 감사합니다
        • 윤상지
          CREATE TABLE `TOPIC` 에서 6번째 줄 `author` 을 `athor` 로 잘못 입력해서 그 이후로 진도를 못나가요 ㅠㅠ 다시 `author`로 수정하는 방법좀 알려주세요..ㅜ
        • 박병진
          감사합니다. 계속 나아가겠습니다.
        • 안다민
          혹시 저처럼 mac 쓰시는 분 중에 zsh: no such file or directory: cd/usr/local/mysql/bin
          에러 계속 뜨시는 분 있나요. 저 SQL만 지금 3번째 넘게 깔고 지우는데 도저히 접속이 안 되네요. 구글링해도 저랑 비슷한 경우가 없는 것 같은데 답변 부탁드려요.
        • 10/9
        • 허우룩
          2020.09.15
        • 권오상
          어렵게 어렵게 여기까지 왔습니다.
          위에 INSERT 에서 id 값을 넣으니까 에러가 나서 id 값을 삭제하고 입력하니까 제대로 되네요.
          감사합니다. 많이 배우고 있습니다.^^
        • Pleasure of Learning
          감사합니다.
        • HyeonHui Jeong
          5/16 어려운 내용인데 쉽게 설명해주려 노력해주셔서 감사합니다ㅠㅠ
        • 코딩영재
          There has been an error.
          Error running /Applications/mampstack-7.3.17-1/ctlscript.sh start: httpd.bin: Syntax error on line 139 of /Applications/mampstack-7.3.17-1/apache2/conf/httpd.conf: Cannot load modules/mod_ssl.so into server: dlopen(/Applications/mampstack-7.3.17-1/apache2/modules/mod_ssl.so, 10): Symbol not found: _syslog$DARWIN_EXTSN\n Referenced from: /Applications/mampstack-7.3.17-1/mysql/lib/libcrypto.1.1.dylib (which was built for Mac OS X 10.13)\n Expected in: /usr/lib/libSystem.B.dylib\n in /Applications/mampstack-7.3.17-1/mysql/lib/libcrypto.1.1.dylib
          The application will exit now.

          mac 사용자입니다 bitnami 재설치했더니 저런 에러가 뜨면서 MySQL이 설치되지않습니다 혹시 도와주실수 있나요??
        • 열심히사는사람
          완료
        • 산노을
          중딩씨 나도 재설치해봤는데 다른 경로로 하라는데 어째야 하죠?
          살려 주세요 !
        • 산노을
          아무리해도 안됩니다.
          C::\Bitnami\wampstack-7.3.16-2\mysql\bin>해 놓고

          mysql -hlocalhost -uroot -p 붙이고
          enter하면

          "내부 또는 외부 명령,실행할 수 있는 프로그램, 또는 배치 파일이 아닙니다."
          라고 뜹니다. 거참!

          Help Me!
        • 중딩
          완료...
          비밀번호 기억했어야 되는데 잘 까먹었습니다
          재설치 하느라 애먹었어여...
        • wibette
          감사합니다. 정말루요. 눈이 뜨여지는 -쪼금씩 ^^- 느낌.
        • myjin
          완료!!
        • 아르하트
          감사합니다^^.
        • 엄청잘될꺼야
          감사합니다. 완료
        • 웹초보
          20191112 완료

          감사합니다.
        • xiubin
          **mysql 서버 접속시 아래와 같은 에러뜨는 경우 (windows)

          " ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) "

          아래 링크 참조해서 해결했습니다. 비밀번호를 리셋하는 방법입니다. 도움이 되시길 바라며 댓글로 작성해둡니다.
          https://dev.mysql.com......tml
        • 들국화
          잘봤습니다
        • 김재원
          테이블 생성에서 막혔습니다. query ok가 안 나옵니다. 영상에서는 맥으로 하고 있는데, 윈도우 프롬프트로 하는거랑 코드가 다른가요?
        • 야근요정
          왜 됬는지를 모르겠지만ㅠㅠ
          완료되썽요!!!! description을 discrip 으로 했더니 오케이쿼리뜸ㅎ
        • 리마인더
          데이터베이스 이론2 중간 비밀번호 설정에서 막힘
          to be continue
        • 셜리
          비번은 말씀해주시는 걸 못들었네요. ㅎㅎㅎ. 동일하게 설정했거든요. 암튼 완료!
        • 셜리
          음... 처음으로 의문이 생기네요 ㅎㅎㅎ 비번은 멀 쓰죠? 제 컴은 비번이 설정이 안되어있는데요.^^;;
        • 예로니
          감사합니다. 덕분에 해결했습니다.
          대화보기
          • 민턴쟁이
            server event 가 아래와 같습니다.
            진도를 못 나가고 있네요 도와주세요

            Starting MySQL Database...
            Exit code: 1
            Stdout:

            Stderr:
            Unknown error starting mysql
          • 민턴쟁이
            bitnami 를 깔때 이상하게 데이터베이스가 에러뜨더니
            역시 데이터베이스 에러가 드네요

            에러 1064
            ㅜㅜ
          • 에러는 그만
            Warning: mysqli_connect(): PHP was built without openssl extension, can't send password encrypted in E:\Bitnami\wampstack-7.1.21-0\apache2\htdocs\php\1.php on line 3라고 계속 뜹니다.

            구글에서는 php.ini에서 extension=php_openssl.dll과 extension=php_mysqli.dll을 주석해야 된다길래 그대로 따라해도 안됩니다. extension_dir="E:\Bitnami\wampstack-7.1.21-0\php\ext"로 바꿨는데도 안되네요...

            문제가 무엇인가요??
          • sung박
            mysql>select id,title,author,created FROM topic셀렉트와 프럼 사이에 컬럼들이 옴
          • HHHHHHHH
            이고잉님 덕분에 너무 잘 공부하고 있습니다

            앱개발에 관련되어있는부분의 지식이 부족하여
            분야가 조금다르지만 이고잉님이라면 어느정도 알고 계시지 않을까 싶어 질문을 드립니다.

            게임을 개발하고 있는데, 많은 게임들이 가지고 있는 기능인 Facebook같은 소셜네트워크와의 연동, 리더보드에 관한 기술적인 부분에 대해서 잘 몰라서 고민이 많습니다.

            이같은 플랫폼과 제 앱을 연동 하려면 API를 보아야 하는 것인가요?
            페이스북 개발자 홈페이지를 둘러보니까 로그인을 연동하려면 Android같은 환경에서 연동시키는 것 처럼 보여서 질문드립니다.

            그렇다면 게임개발은 개발대로하고 API연동을 할 때에는 android나 IOS의 언어를 꼭 알고있어야 하는 것인지 궁금합니다
          • egoing
            윈도우에선 ./ 없이 하셔야 합니다~
            대화보기
            • 초보코딩
              아래에 댓글 남겼다가 다시 씁니다.

              제가 새롭게 시도하면 또 똑같은 에러가 뜨더라구요.
              저는 우분투 사용자인데요

              지금 이고잉님께서 ./mysql -hlocalhost -uroot -p 라고 하셨는데 항상 ./ 를 치면 에러가 났네요

              그냥 /opt/lampstack-7.2.0-0/mysql/bin$ mysql -u root -p 치고 들어가면 잘 들어가집니다....

              문제 해결해서 기쁘네요
            버전 관리
            egoing
            현재 버전
            선택 버전
            graphittie 자세히 보기