Re: running a mysql query inside a loop of another without a sync error
>From 1 feet, what you are attempting to do looks like it would be very easily accomplished with a join, leaving you with 1 result set to process. I realize that isn't the question, but it might be a solution. - michael dykman On Wed, Jan 19, 2011 at 9:54 PM, Delan Azabani wrote: > Hi all, > > I'm using MySQL with C in a CGI application. I hope this is the right > list to ask for help. > > If I have this simplified code: > > MYSQL_RES *res; > MYSQL_ROW row; > mysql_query(mysql, "some select query"); > res = mysql_use_result(mysql); > while (row = mysql_fetch_row(res)) { > MYSQL_RES *res2; > MYSQL_ROW row2; > mysql_query(mysql, "some other select query using an id from the > first"); > res2 = mysql_use_result(mysql); > /* ... */ > mysql_free_result(res2); > } > mysql_free_result(res); > > Whenever I run the second query, inside the loop, I get the nasty > 'commands out of sync' error. How can I run a select query while in a > loop fetching rows from another select query? Or, do I have to fetch all > the rows completely first and store them in memory (which wouldn't be > very 'nice' to do)? > > If someone could help me with this problem, it would be greatly appreciated. > > -- > Thanks and best regards, > Delan Azabani > http://azabani.com/ > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: http://lists.mysql.com/mysql?unsub=mdyk...@gmail.com > > -- - michael dykman - mdyk...@gmail.com May the Source be with you. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: running a mysql query inside a loop of another without a sync error
Hello Delan, On 1/19/2011 21:54, Delan Azabani wrote: Hi all, I'm using MySQL with C in a CGI application. I hope this is the right list to ask for help. If I have this simplified code: MYSQL_RES *res; MYSQL_ROW row; mysql_query(mysql, "some select query"); res = mysql_use_result(mysql); while (row = mysql_fetch_row(res)) { MYSQL_RES *res2; MYSQL_ROW row2; mysql_query(mysql, "some other select query using an id from the first"); res2 = mysql_use_result(mysql); /* ... */ mysql_free_result(res2); } mysql_free_result(res); Whenever I run the second query, inside the loop, I get the nasty 'commands out of sync' error. How can I run a select query while in a loop fetching rows from another select query? Or, do I have to fetch all the rows completely first and store them in memory (which wouldn't be very 'nice' to do)? If someone could help me with this problem, it would be greatly appreciated. The mysql object you are using for your connection can only have one active query or result on it at a time. To have two sets of results working, you need a second independent connection to the MySQL server http://dev.mysql.com/doc/refman/5.5/en/c-api-data-structures.html ### MYSQL This structure represents a handle to one database connection. It is used for almost all MySQL functions. You should not try to make a copy of a MYSQL structure. There is no guarantee that such a copy will be usable. ### http://dev.mysql.com/doc/refman/5.5/en/mysql-real-connect.html ### The first parameter should be the address of an existing MYSQL structure. Before calling mysql_real_connect() you must call mysql_init() to initialize the MYSQL structure. You can change a lot of connect options with the mysql_options() call. See Section 22.9.3.49, “mysql_options()”. ### http://dev.mysql.com/doc/refman/5.5/en/threaded-clients.html ### Two threads can't send a query to the MySQL server at the same time on the same connection. In particular, you have to ensure that between calls to mysql_query() and mysql_store_result() no other thread is using the same connection. ### This same rule applies to attempting to process more than one query on the same connection. You must complete the first query before starting the second or you must open a separate connection to handle the second query. Yours, -- Shawn Green MySQL Principal Technical Support Engineer Oracle USA, Inc. Office: Blountville, TN -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
running a mysql query inside a loop of another without a sync error
Hi all, I'm using MySQL with C in a CGI application. I hope this is the right list to ask for help. If I have this simplified code: MYSQL_RES *res; MYSQL_ROW row; mysql_query(mysql, "some select query"); res = mysql_use_result(mysql); while (row = mysql_fetch_row(res)) { MYSQL_RES *res2; MYSQL_ROW row2; mysql_query(mysql, "some other select query using an id from the first"); res2 = mysql_use_result(mysql); /* ... */ mysql_free_result(res2); } mysql_free_result(res); Whenever I run the second query, inside the loop, I get the nasty 'commands out of sync' error. How can I run a select query while in a loop fetching rows from another select query? Or, do I have to fetch all the rows completely first and store them in memory (which wouldn't be very 'nice' to do)? If someone could help me with this problem, it would be greatly appreciated. -- Thanks and best regards, Delan Azabani http://azabani.com/ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: Can't read dir of '.' (errno: 13)
One simple querstion: did you try "chown -R mysql:mysql /your/whole/data/dir" if not do this and after that the problem is gone or not - if it's gone all is ok, if not let us look for other ideas And yes it is possible tha mysql can authenticate the user when bad permissions came after caching some information and if your query nneeds access to non cached data you have a problem Am 19.01.2011 20:56, schrieb Joerg Bruehe: > Hi ! > > > Jerry Schwartz wrote: >>> -Original Message- >>> From: Joerg Bruehe [mailto:joerg.bru...@oracle.com] >>> Sent: Wednesday, January 19, 2011 10:43 AM >>> To: mysql@lists.mysql.com >>> Cc: Jerry Schwartz >>> Subject: Re: Can't read dir of '.' (errno: 13) >>> >>> Hi! >>> >>> >>> Jerry Schwartz wrote: > -[[...]] > [JS] I have a related question: how can MySQL authenticate a user if file system permissions won't let it read any databases? >>> To me, your question sounds like you forgot the difference between >>> server and client: >>> >> [JS] I don't think so, but perhaps I misunderstood the source of the error >> message. >> >> mysql> show databases ; >> ERROR 1018 (HY000): Can't read dir of '.' (errno: 13) >> >> Are you saying that the mysql CLI needs to read some directory ('.', in this >> case) in order to send mysqld a simple query like SHOW DATABASES? I would >> hope >> it doesn't need a temporary file for that. > > No, I didn't say that. > > You say that "the mysql CLI ... send(s) mysqld a simple query ...", and > that is correct: the client ("mysql") sends the command "show databases" > to the server ("mysqld"). > To process this, the server has to check the file(s) and directory(ies) > used to store the database contents, and one of those actions is to read > the current directory. > >> >> Who is issuing the errno 13, the client or the daemon? > > AIUI, it is the server, encountering a permission problem. > So the server encounters a problem, and it reports this back to the > client who will then output the message. > > > Your question that triggered my original reply was: >how can MySQL authenticate a user if file system permissions >won't let it read any databases? > > My original reply tried to make it obvious that the user (who is to be > authenticated) is just a database concept, so this (maybe non-existing) > user's (possibly missing) permissions in the operating system to read > any OS object (file, directory) do not matter at all when the MySQL > server does the authentication. > It is the server (process) that needs the permissions to read (and > write) database directories and files. > > Of course, if these permissions are missing, then the server cannot > operate (and so also cannot authenticate a user), but that is a question > of server setup and not of database user privileges. > > > HTH, > Jörg > -- Mit besten Grüßen, Reindl Harald the lounge interactive design GmbH A-1060 Vienna, Hofmühlgasse 17 CTO / software-development / cms-solutions p: +43 (1) 595 3999 33, m: +43 (676) 40 221 40 icq: 154546673, http://www.thelounge.net/ signature.asc Description: OpenPGP digital signature
RE: Can't read dir of '.' (errno: 13)
Regards, Jerry Schwartz Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 E-mail: je...@gii.co.jp Web site: www.the-infoshop.com >-Original Message- >From: Joerg Bruehe [mailto:joerg.bru...@oracle.com] >Sent: Wednesday, January 19, 2011 2:56 PM >To: Jerry Schwartz >Cc: mysql@lists.mysql.com >Subject: Re: Can't read dir of '.' (errno: 13) > >Hi ! > > >Jerry Schwartz wrote: >>> -Original Message- >>> From: Joerg Bruehe [mailto:joerg.bru...@oracle.com] >>> Sent: Wednesday, January 19, 2011 10:43 AM >>> To: mysql@lists.mysql.com >>> Cc: Jerry Schwartz >>> Subject: Re: Can't read dir of '.' (errno: 13) >>> >>> Hi! >>> >>> >>> Jerry Schwartz wrote: > -[[...]] > [JS] I have a related question: how can MySQL authenticate a user if file system permissions won't let it read any databases? >>> To me, your question sounds like you forgot the difference between >>> server and client: >>> >> [JS] I don't think so, but perhaps I misunderstood the source of the error >> message. >> >> mysql> show databases ; >> ERROR 1018 (HY000): Can't read dir of '.' (errno: 13) >> >> Are you saying that the mysql CLI needs to read some directory ('.', in >> this >> case) in order to send mysqld a simple query like SHOW DATABASES? I would >hope >> it doesn't need a temporary file for that. > >No, I didn't say that. > >You say that "the mysql CLI ... send(s) mysqld a simple query ...", and >that is correct: the client ("mysql") sends the command "show databases" >to the server ("mysqld"). >To process this, the server has to check the file(s) and directory(ies) >used to store the database contents, and one of those actions is to read >the current directory. > >> >> Who is issuing the errno 13, the client or the daemon? > >AIUI, it is the server, encountering a permission problem. >So the server encounters a problem, and it reports this back to the >client who will then output the message. > > >Your question that triggered my original reply was: > how can MySQL authenticate a user if file system permissions > won't let it read any databases? > >My original reply tried to make it obvious that the user (who is to be >authenticated) is just a database concept, so this (maybe non-existing) >user's (possibly missing) permissions in the operating system to read >any OS object (file, directory) do not matter at all when the MySQL >server does the authentication. >It is the server (process) that needs the permissions to read (and >write) database directories and files. > >Of course, if these permissions are missing, then the server cannot >operate (and so also cannot authenticate a user), but that is a question >of server setup and not of database user privileges. > [JS] Sorry, that still doesn't make sense to em. To authenticate the user, mysqld needs to read the mysql database. That is also where the databases are listed (in `mysql`.`db`). If the daemon can read `mysql`.`user`, why can't it read `mysql`.`db`? It's a MyISAM database, so everything is in the same file. What am I missing? Does SHOW DATABASES do something other than pull the database names out of `mysql`.`db`? > >HTH, >Jörg > >-- >Joerg Bruehe, MySQL Build Team, joerg.bru...@oracle.com >ORACLE Deutschland B.V. & Co. KG, Komturstrasse 18a, D-12099 Berlin >Geschaeftsfuehrer: Juergen Kunz, Marcel v.d. Molen, Alexander v.d. Ven >Amtsgericht Muenchen: HRA 95603 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: Can't read dir of '.' (errno: 13)
Hi ! Jerry Schwartz wrote: >> -Original Message- >> From: Joerg Bruehe [mailto:joerg.bru...@oracle.com] >> Sent: Wednesday, January 19, 2011 10:43 AM >> To: mysql@lists.mysql.com >> Cc: Jerry Schwartz >> Subject: Re: Can't read dir of '.' (errno: 13) >> >> Hi! >> >> >> Jerry Schwartz wrote: -[[...]] >>> [JS] I have a related question: how can MySQL authenticate a user if file >>> system permissions won't let it read any databases? >> To me, your question sounds like you forgot the difference between >> server and client: >> > [JS] I don't think so, but perhaps I misunderstood the source of the error > message. > > mysql> show databases ; > ERROR 1018 (HY000): Can't read dir of '.' (errno: 13) > > Are you saying that the mysql CLI needs to read some directory ('.', in this > case) in order to send mysqld a simple query like SHOW DATABASES? I would > hope > it doesn't need a temporary file for that. No, I didn't say that. You say that "the mysql CLI ... send(s) mysqld a simple query ...", and that is correct: the client ("mysql") sends the command "show databases" to the server ("mysqld"). To process this, the server has to check the file(s) and directory(ies) used to store the database contents, and one of those actions is to read the current directory. > > Who is issuing the errno 13, the client or the daemon? AIUI, it is the server, encountering a permission problem. So the server encounters a problem, and it reports this back to the client who will then output the message. Your question that triggered my original reply was: how can MySQL authenticate a user if file system permissions won't let it read any databases? My original reply tried to make it obvious that the user (who is to be authenticated) is just a database concept, so this (maybe non-existing) user's (possibly missing) permissions in the operating system to read any OS object (file, directory) do not matter at all when the MySQL server does the authentication. It is the server (process) that needs the permissions to read (and write) database directories and files. Of course, if these permissions are missing, then the server cannot operate (and so also cannot authenticate a user), but that is a question of server setup and not of database user privileges. HTH, Jörg -- Joerg Bruehe, MySQL Build Team, joerg.bru...@oracle.com ORACLE Deutschland B.V. & Co. KG, Komturstrasse 18a, D-12099 Berlin Geschaeftsfuehrer: Juergen Kunz, Marcel v.d. Molen, Alexander v.d. Ven Amtsgericht Muenchen: HRA 95603 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: Can't read dir of '.' (errno: 13)
>-Original Message- >From: Joerg Bruehe [mailto:joerg.bru...@oracle.com] >Sent: Wednesday, January 19, 2011 10:43 AM >To: mysql@lists.mysql.com >Cc: Jerry Schwartz >Subject: Re: Can't read dir of '.' (errno: 13) > >Hi! > > >Jerry Schwartz wrote: >>> -[[...]] >>> >> [JS] I have a related question: how can MySQL authenticate a user if file >> system permissions won't let it read any databases? > >To me, your question sounds like you forgot the difference between >server and client: > [JS] I don't think so, but perhaps I misunderstood the source of the error message. mysql> show databases ; ERROR 1018 (HY000): Can't read dir of '.' (errno: 13) Are you saying that the mysql CLI needs to read some directory ('.', in this case) in order to send mysqld a simple query like SHOW DATABASES? I would hope it doesn't need a temporary file for that. Who is issuing the errno 13, the client or the daemon? Regards, Jerry Schwartz Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 E-mail: je...@gii.co.jp Web site: www.the-infoshop.com >- The MySQL server processes always run as the same operating system > user (typically: "mysql"), and basic setup must ensure they have > access rights to all files storing the database contents. > >- The client processes run on any machine (local or remote) as any user, > and that OS user may be totally unrelated to the database user that > will be authenticated. > >Just assume some application (with privilege checks!) accessed via the >web: The web server (Apache, ...) executing the PHP (or other) code is >running with some OS user ID which is the same for all application >(database) users, and there is no need to define those application users >on the machine running the server processes of Apache or MySQL. > > >HTH, >Jörg > >-- >Joerg Bruehe, MySQL Build Team, joerg.bru...@oracle.com >ORACLE Deutschland B.V. & Co. KG, Komturstrasse 18a, D-12099 Berlin >Geschaeftsfuehrer: Juergen Kunz, Marcel v.d. Molen, Alexander v.d. Ven >Amtsgericht Muenchen: HRA 95603 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: Can't read dir of '.' (errno: 13)
Hi! Jerry Schwartz wrote: >> -[[...]] >> > [JS] I have a related question: how can MySQL authenticate a user if file > system permissions won't let it read any databases? To me, your question sounds like you forgot the difference between server and client: - The MySQL server processes always run as the same operating system user (typically: "mysql"), and basic setup must ensure they have access rights to all files storing the database contents. - The client processes run on any machine (local or remote) as any user, and that OS user may be totally unrelated to the database user that will be authenticated. Just assume some application (with privilege checks!) accessed via the web: The web server (Apache, ...) executing the PHP (or other) code is running with some OS user ID which is the same for all application (database) users, and there is no need to define those application users on the machine running the server processes of Apache or MySQL. HTH, Jörg -- Joerg Bruehe, MySQL Build Team, joerg.bru...@oracle.com ORACLE Deutschland B.V. & Co. KG, Komturstrasse 18a, D-12099 Berlin Geschaeftsfuehrer: Juergen Kunz, Marcel v.d. Molen, Alexander v.d. Ven Amtsgericht Muenchen: HRA 95603 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: Can't read dir of '.' (errno: 13)
>-Original Message- >From: Adarsh Sharma [mailto:adarsh.sha...@orkash.com] >Sent: Wednesday, January 19, 2011 12:45 AM >To: mysql@lists.mysql.com >Subject: Can't read dir of '.' (errno: 13) > >Dear all, > >I am facing the issue mentioned below while issuing show databases command. > > >root@s7-dt-bse:~# 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.41-3ubuntu12.8 (Ubuntu) > >Type 'help;' or '\h' for help. Type '\c' to clear the current input >statement. > >mysql> show databases ; >ERROR 1018 (HY000): Can't read dir of '.' (errno: 13) >mysql> show databases; >ERROR 1018 (HY000): Can't read dir of '.' (errno: 13) >mysql> > >My Mysql data dir is /hdd2-1/myisam_data/* > >Mysql is the owner and group of myisam_data folder. > >Can I know why it occurs and how to debug it. > [JS] I have a related question: how can MySQL authenticate a user if file system permissions won't let it read any databases? Regards, Jerry Schwartz Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 E-mail: je...@gii.co.jp Web site: www.the-infoshop.com > >Thanks & Regards > >Adarsh Sharma > >-- >MySQL General Mailing List >For list archives: http://lists.mysql.com/mysql >To unsubscribe:http://lists.mysql.com/mysql?unsub=je...@gii.co.jp -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: Can't read dir of '.' (errno: 13)
Check owner of the MySQL data directory. 2011/1/19 Pintér Tibor > > mysql> show databases ; > > ERROR 1018 (HY000): Can't read dir of '.' (errno: 13) > > mysql> show databases; > > ERROR 1018 (HY000): Can't read dir of '.' (errno: 13) > > mysql> > > $ perror 13 > OS error code 13: Permission denied > > t > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe:http://lists.mysql.com/mysql?unsub=yogeshk...@gmail.com > >
Re: ERROR 1 (HY000): Can't create/write to file '/var/lib/mysql/#sql_9e1_0.MYI' (Errcode: 13)
Hi everybody! Peng Yu wrote: > Hi, > > I run the following command. But I got the following error. I'm not > sure what causes the problem. I have seen the same issue before, but > it disappeared even I didn't take any action. Could anybody let me > know how to fix the problem? > > mysql -ugenome -hgenome-mysql.cse.ucsc.edu mm9 -A > > mysql> select geneName as symbol, name as refSeq, chrom, strand, > txStart, txEnd from refFlat group by refSeq having count(*)=1; > ERROR 1 (HY000): Can't create/write to file > '/var/lib/mysql/#sql_9e1_0.MYI' (Errcode: 13) > "Errcode" is what mySQL writes for an "errno" value. First, you need to find out what the error number 13 means: joerg@machine:~$ fgrep 13 /usr/include/asm-generic/errno-base.h #define EACCES 13 /* Permission denied */ Then (unless you know that already), check the "man" pages to find when the calls would return EACCESS. In this case, the candidate calls are "creat()" and "write()". man 2 write the output doesn't mention EACCESS. man 2 creat will tell you this: ERRORS EACCES The requested access to the file is not allowed, or search permission is denied for one of the directories in the path prefix of pathname, or the file did not exist yet and write access to the parent directory is not allowed. (See also path_resolution(7).) So it is a permission issue for either the file, or the directory hierarchy leading to it. See the other replies for the specific things to check. Regards, Jörg -- Joerg Bruehe, MySQL Build Team, joerg.bru...@oracle.com ORACLE Deutschland B.V. & Co. KG, Komturstrasse 18a, D-12099 Berlin Geschaeftsfuehrer: Juergen Kunz, Marcel v.d. Molen, Alexander v.d. Ven Amtsgericht Muenchen: HRA 95603 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org