MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Michael Stassen Date:July 25 2004 12:06am
Subject:Re: specify database dir
View as plain text  
Adrien Saladin wrote:

> Hello,
> 
> I'm quite new to mysql so I apologize if my question seems stupid. I hope it 
> is the right mailing list for that question. 
> 
> I'm using the mysql embedded library (libmysqld) with a small c++ program. 
> This program created a new database in its directory and I would like to use 
> this database like any other normal database. 
> 
> I found a complicated way to do this by copying the /var/lib/mysql/mysql 
> directory and files to my program's directory, changing owner and group to 
> 'mysql' and then running mysqld with "--datadir=."

A symbolic link in the mysql data directory pointing to the program's 
directory would work as well.  Then you wouldn't need --datadir, nor would 
you have to mess with any other db to accomodate your program.

> It seems to work fine except for this message:
> --------
> mysql> use dbtest;
> Reading table information for completion of table and column names
> You can turn off this feature to get a quicker startup with -A
> 
> Database changed
> mysql>
> ---------

What's wrong with the message?  No error is reported.  Everything seems fine.

> As you can see it is quite complicated. When I need to run my program, I have 
> to change the owner and group for the database again. 

Why not add yourself to the mysql group and make the program's db 
group-readable and writeable?  Or change the group of the db files and 
directory to a new group, make them group-readable and writeable, and add 
yourself to that group.  Or make the program's files owned by you but in the 
mysql group, and make them group-readable and writeable.  (I'd probably go 
with the 3rd way.)

> I tried  at least to make mysqld use the database without changing its owner 
> like this: 
> ----
> mysqld --user adrien --datadir=.  &

I'm sure we could get this to work, but I don't think it's the best 
solution.  Better to keep mysql running as mysql, and fix the problem 
through group permissions.

> [1] 6633
> root@omicron:/home/adrien/c++/mysqltest# Warning: Ignoring user change to 
> 'adrien' because the user was set to 'mysql' earlier on the command line
> mysqld: ready for connections.
> Version: '4.0.20-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 0
> ---
> but I cannot use the database:
> -----
> mysql> use ;
> Can't read dir of './dbtest/' (Errcode: 13)
> Database changed
> mysql> show tables;
> ERROR 12: Can't read dir of './dbtest/' (Errcode: 13)
> mysql>
> -----
> 
> Could somebody tell me a better way to use the local database "dbtest" ?
> 
> Thanks.
> Adrien

Michael

Thread
specify database dirAdrien Saladin24 Jul
  • Re: specify database dirMichael Stassen25 Jul