WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: MySQL & bootsync.sh  (Read 3855 times)

Offline nickjf20

  • Newbie
  • *
  • Posts: 25
MySQL & bootsync.sh
« on: August 06, 2011, 09:31:16 AM »
Hi,

I'm trying to get MySQL working so that databases and users are persistent across boot.

So far I have all the steps worked out manually as follows;

1. Create  a database and a user with full privileges to said database.
2. Copy over /path/to/my.cnf and /path/to/mysql to a location on my hdd
3. symlink said files on my hdd over to their 'correct' positions through bootsync.sh

I did have the symlink commands in bootlocal.sh to delete the auto generated my.cnf and mysql directory, and then symlink the hdd files over, but by this point the mysql daemon had already loaded and so didn't take the settings from my HDD files.

My problem is that I am scripting all this for ease of use, and a command such as

Code: [Select]
echo "ln -sf /mnt/sda1/lost+found/my.cnf /usr/local/etc/my.cnf" >> /opt/bootsync.sh
simply returns '-sh: can't create /opt/bootsync.sh: Permission denied'

Any ideas ? I tried restarting mysqld_safe when using the bootlocal.sh method, but this simply seems to stop mysql from working.


Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11587
Re: MySQL & bootsync.sh
« Reply #1 on: August 06, 2011, 12:30:44 PM »
Hi nickjf20
I just checked the permissions for my bootsync.sh file and only root has write permission. Try using

sudo editor /opt/bootsync.sh

and place your commands where you want them.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: MySQL & bootsync.sh
« Reply #2 on: August 06, 2011, 12:44:48 PM »
There was some discussion with mysql auto-starting, with problems like that. I don't recall what the outcome was, but you can work around that in many ways - kill the autostarted instance, edit the extension not to autostart...
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11587
Re: MySQL & bootsync.sh
« Reply #3 on: August 06, 2011, 01:08:36 PM »
Hi nickjf20
I just reread your last post.
Quote
My problem is that I am scripting all this for ease of use, and a command such as

Code:
echo "ln -sf /mnt/sda1/lost+found/my.cnf /usr/local/etc/my.cnf" >> /opt/bootsync.sh

simply returns '-sh: can't create /opt/bootsync.sh: Permission denied'

Even if it worked it's a bad idea. Due to back up and restore, your bootsync file would start to grow
because you would keep on appending the same line over and over. Plus if bootsync is executing
at the time you should not be trying to write to it.

Offline nickjf20

  • Newbie
  • *
  • Posts: 25
Re: MySQL & bootsync.sh
« Reply #4 on: August 06, 2011, 01:27:18 PM »
@Rich The problem has never been editing bootsync.sh through an editor such as nano, it's just that using echo to 'inject' lines of text into it doesn't work, even when run as root.

As for curaga's suggestion, when I run
Code: [Select]
/usr/local/bin/mysqld_safe restart as root and as tc, it 'breaks' mysql to the extent of no command working.

Please could you give me the correct commands ?

EDIT: just saw your last post -- the script (I can post it if you want) has checks to see whether it has been run before, so there is no chance of bootsync.sh growing out of proportion.

I have had a really good look round google, and all lead to the latest reply early july that the maintainer of MySQL.tcz will be updating it to 'fit in' with the tiny core persistence ethos.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11587
Re: MySQL & bootsync.sh
« Reply #5 on: August 06, 2011, 01:41:57 PM »
Hi nickjf20
Quote
EDIT: just saw your last post -- the script (I can post it if you want) has checks to see whether it has been run before, so there is no chance of bootsync.sh growing out of proportion.

Then why not simply let that script create the link instead of having it append the command to bootsync?

Offline nickjf20

  • Newbie
  • *
  • Posts: 25
Re: MySQL & bootsync.sh
« Reply #6 on: August 06, 2011, 01:59:47 PM »
The script doesn't run on boot and needs some other method of creating the symlinks on boot.

adding them to bootlocal.sh is too late in the booting process -- mysqld creates 'generic' my.cnf and databases which obviously do not contain my data !

I had it set to remove the generic DBs and then symlink mine in, but restarting mysql as above doesn't seem to work.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11587
Re: MySQL & bootsync.sh
« Reply #7 on: August 06, 2011, 02:21:47 PM »
Hi nickjf20
See if something in this link is helpful.
http://forum.tinycorelinux.net/index.php?topic=7008.0

Offline nickjf20

  • Newbie
  • *
  • Posts: 25
Re: MySQL & bootsync.sh
« Reply #8 on: August 07, 2011, 05:27:41 PM »
I hope to have it all worked out by tomorrow night -- I'll post back a definitive guide if you want it included in the wiki ?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11587
Re: MySQL & bootsync.sh
« Reply #9 on: August 07, 2011, 05:33:33 PM »
Hi nickjf20
Additions to the Wiki are always welcome and appreciated.

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Re: MySQL & bootsync.sh
« Reply #10 on: August 07, 2011, 06:19:57 PM »
... The problem has never been editing bootsync.sh through an editor such as nano, it's just that using echo to 'inject' lines of text into it doesn't work, even when run as root. ...

nickjf20: The reason that sudo echo SOME_TEXT > FILE_OWNED_BY_ROOT fails when run in a shell of a non-root user is that the 'echo SOME_TEXT' gets executed as 'root' but the output redirection is handled by the shell (of the non-root user), which causes the "problem" you've observed.

If you still wonder how to solve this little problem in the future I'd like to suggest the following:
    echo SOME_TEXT | sudo tee FILE_OWNED_BY_ROOT > /dev/null
and when you want to append instead of overwriting just add the '-a' option to the 'tee' command. If you don't care about that 'SOME_TEXT' showing up as output somewhere you could also drop the output redirection (to '/dev/null').

An alternative suggestion would be to use sudo sh -c "echo SOME_TEXT > FILE_OWNED_BY_ROOT", but that can become tricky if your command would be more complicated than a simple 'echo' and you need quoting inside the double quotes. Not a "biggie" if one pays attention to it, but I at least have now developed a preference for the solution with the 'tee'.


Offline nickjf20

  • Newbie
  • *
  • Posts: 25

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11587
Re: MySQL & bootsync.sh
« Reply #12 on: August 09, 2011, 07:56:28 PM »
Hi nickjf20
Nice write up, very clear and concise. One minor point, under  Filetool method  the entries for
/opt/.filetool,lst  should not have a leading slash.