mysql_real_connect() 오류..

jinushun의 이미지

안녕하세요..

mysql_real_connect 함수에서 호스트명에 localhost 라고 쓰면 접속이 잘되고,

해당 아이피를 쓰면 접속이 안되는군요?

해당아이피는 localhost 의 해당아이피로, 사설아이피 192. 대역입니다.

왜 이런경우가생기는 것일가요?

뜨는 오류는 아래와 같습니다.

ERROR 2013(Lost Connection to mysql server during query)

미리 감사드립니다. :o

정태영의 이미지

mysql 디비의.. user테이블을 보시면...
host란 부분이 있습니다..

거기서 아이피로도 열어주시면 될겁니다 :)
grant all on 디비이름 to 아이디@아이피 identified by '비밀번호';

한번 날려주시면 :D
아이디@%라면 어디서 접근하든 허용하겠다는거구요..

오랫동안 꿈을 그리는 사람은 그 꿈을 닮아간다...

http://mytears.org ~(~_~)~
나 한줄기 바람처럼..

jinushun의 이미지

답변 감사드립니다.

간단한게 안되니 돌겠군요 ㅋㅋ
:oops:
권한문제인거같아 이것저것 해보던중 답글이 올라와있네요.

그런데도 안됩니다.

-새로운계정 추가-

grant all privileges on mysql.* to jinushun@"%" identified by 'password'

계정결과

mysql> select user,host,password from user;
+----------+-----------+------------------+
| user     | host      | password         |
+----------+-----------+------------------+
| root     | localhost | 690a7466206fcb04 |
| root     | jinux     | 690a7466206fcb04 |
|          | localhost |                  |
|          | jinux     |                  |
| jinushun | %         | 690a7466206fcb04 |
+----------+-----------+------------------+
5 rows in set (0.00 sec)

보시다시피 잘 추가되었습니다.

테스트프로그램 실행결과

[root@jinux sql_test]# ./test
mysql_real_connect()연결 실패 :
Error 2013 (Lost connection to MySQL server during query)

수행 코드입니다.




#include <stdio.h>
#include <mysql.h>
#define mys_host_name "192.168.17.128" /* 호스트*/
//#define mys_host_name "localhost"

#define mys_user_name "jinushun" 
#define mys_password "password"
#define mys_db_name "mysql" 

MYSQL *conn;

int main (int argc,char *argv [])
{
        conn = mysql_init (NULL);

        if (conn ==NULL)
        {
                fprintf (stderr,"mysql_init()실패 ( 메모리 부족 out of memory)\n ");
                exit (1);
        }

        if (mysql_real_connect (
                conn,
                mys_host_name,
                mys_user_name,
                mys_password,
                mys_db_name,
                3306,
                NULL,
                0)
                ==NULL)
                {
                        fprintf (stderr,"mysql_real_connect()연결 실패 :\nError %u (%s)\n ", mysq
l_errno (conn),mysql_error (conn));
                        exit (1);
                }else{
                        if (mysql_query (conn,"INSERT INTO address VALUES('jiyeon','miraeeset','0
17-631-0000')")!=0)
                        {
                                printf ("INSERT 실패");
                        }
                        else
                        {
                                printf ("INSERT 성공:%lu rows affected \n ",(unsigned long)mysql_
affected_rows (conn));
                        }
                }
mysql_close (conn);
exit (0);
}

가르침을 주시면 감사하겠습니다.

user 테이블에 jinushun 을 % 로 줘도 아이피, localhost 둘다 접속이 안되더군요..

jinushun 을 localhost 로 설정하니 localhost 는 되었습니다.

그럼 %는 localhost 는 포함하지 않는다고 보면되는건가요?

그렇다손치더라도 아이피를 치면 왜 안되는지 -_-;; :twisted:

----------------------------
www.nate.com
----------------------------

leilei의 이미지

가끔 제가 하는 실수인데..
reload를 안하신게 아닐까 합니다만... :)

정태영의 이미지

leilei wrote:
가끔 제가 하는 실수인데..
reload를 안하신게 아닐까 합니다만... :)

update가 아니라 grant라면.. 권한을 flush해줘서 별 문제 없을듯 한데
알수 없군요 =3=33

오랫동안 꿈을 그리는 사람은 그 꿈을 닮아간다...

http://mytears.org ~(~_~)~
나 한줄기 바람처럼..

leilei의 이미지

앗.. 해서 뒤져보니..

Quote:

If you modify the grant tables using GRANT, REVOKE, or SET PASSWORD, the server notices these changes and reloads the grant tables into memory again immediately.

If you modify the grant tables directly using statements such as INSERT, UPDATE, or DELETE, your changes have no effect on privilege checking until you either restart the server or tell it to reload the tables. To reload the grant tables manually, issue a FLUSH PRIVILEGES statement or execute a mysqladmin flush-privileges or mysqladmin reload command.

이렇다네요..

역시 선무당이 사람 잡는군요.. :oops:

leilei의 이미지

헷소리를 했기 땜시... :oops:
좀 더 뒤져보니 이런 이야기가 있네요..

[url]
http://dev.mysql.com/doc/mysql/en/Gone_away.html
[/url]

끝 부분에..

Quote:

I was getting the ``Connection was lost during query'' message instantly whenever I tried to connect to the mysql daemon by TCP/IP. I finally traced it down to the TCP wrappers system (tcpd), which uses the hosts_access(5) system to allow or disallow connections.

If you're running into this problem on a Linux or similar system, be sure to add this to your /etc/hosts.allow file:

mysqld : ALL : ALLOW
mysqld-max : ALL : ALLOW

and similar for the other MySQL daemons.

Notes: The examples above are the simplest case, telling tcpd to allow connections from anywhere. You may wish to use a more appropriate choice of permissible sources instead of ALL. Just make sure that localhost and the IP address (numeric or DNS) of the interface by which you connect are specified.

Gory details of all this are in hosts_access(5)

Ray Simard

이런 글이 읽는데 참고해 보세요..

jinushun의 이미지

답변 감사합니다. :cry:

해결이 안되네요.

약속이 있어 퇴근할렵니다.

DB는 첨이라 근데 생각해 보니 vmware 라 그런가 -_-;; 이젠 별생각까지 다 드는군요 ㅋㅋㅋ

다른 리눅스 서버에서 테스트를 위해 컴파일을 날렸습니다.

근데 에러가...레드햇9인데.. vmware 는 한컴3.0이었습니다.

에러는 아래와 같군요.

[root@RC#1 jinushun]# gcc -o test -I/usr/include/mysql -L/usr/lib/mysql test.c -lmysql
client
/usr/lib/mysql/libmysqlclient.a(my_compress.o)(.text+0xbc): In function `my_compress_a
lloc':
: undefined reference to `compress'
/usr/lib/mysql/libmysqlclient.a(my_compress.o)(.text+0x13a): In function `my_uncompres
s':
: undefined reference to `uncompress'
collect2: ld returned 1 exit status

뭘까요 -_-;;

nm을 쳐봐도 잘 모르겠습니다.

가르침을 주십시오 -_-;; :P

----------------------------
www.nate.com
----------------------------

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.