mysql init-file config option giving file not found error

101

Thanks @quanta, the problem was indeed apparmor.

To fix the issue:

Edit the mysql apparmor file:

sudo emacs -nw /etc/apparmor.d/usr.sbin.mysqld

Include the folder where your init-file lives with the *.sql extension:

...
/usr/sbin/mysqld {
    /var/log/mysql.log rw,
    /var/log/mysql.err rw,
    ;/var/lib/mysql/ r,
    /var/lib/mysql/** rwk,
    /var/log/mysql/ r,
    /var/log/mysql/* rw,
    /{,var/}run/mysqld/mysqld.pid w,
    /{,var/}run/mysqld/mysqld.sock w,

    /sys/devices/system/cpu/ r,

    # I added to allow my init-file script to run
    /etc/mysql/*.sql r,
}

And then make AppArmor reload the profiles.

# sudo /etc/init.d/apparmor reload

Then reload mysql:

sudo /etc/init.d/mysql restart

Now the init-file gets executed. Yay!

Share:
101

Related videos on Youtube

razor_ray
Author by

razor_ray

Updated on September 18, 2022

Comments

  • razor_ray
    razor_ray over 1 year

    I'm making a Microsoft Word addin that integrates with our EDRMS software.

    On this addin, there is a button that will create a new Word Document and save it into the EDRMS.

    However, this button is also available when an existing Document is opened too.

    I want to be able to add some sort of validation so that if the User clicks on the "Create New" button on an existing Document, a message box appears saying that the Document already exists.

    I have been using the foreach loop, which does not work well as it stops at the first result.

    What is the best loop that I can use that will go through all the results first then determine if the document exists or if a new document can be created.

    My code is below:

        private void btnNewDoc_Click(object sender, EventArgs e)
        {
            try
            {
                string docName = Globals.ThisAddIn.Application.ActiveDocument.Name;
    
                string res = Path.GetFileNameWithoutExtension(docName);
    
                string fileloc = Path.GetFullPath(docName);
    
                //searches through all existing documents that are checked out to me
                TrimMainObjectSearch recser = new TrimMainObjectSearch(db, BaseObjectTypes.Record);
                recser.SetSearchString("checkedOutBy:me");
    
                foreach (Record resultRecord in recser)
                {
                    //if the document doesnt appear in the checked out results, then create the new document
                    if (res != resultRecord.Title)
                    {
                        //code to create the new doc
                    }
                    //otherwise display a message
                    else
                    {
                        MessageBox.Show("This is an existing document - " + resultRecord.Number.ToString());
                    }
                }
    
            }
    
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    
    • Greg Petersen
      Greg Petersen over 12 years
      What is the output of file /etc/mysql/mysqlinit.sql?
    • Tom
      Tom over 12 years
      file /etc/mysql/mysqlinit.sql gives "/etc/mysql/mysqlinit.sql: ASCII text, with no line terminators"
    • Greg Petersen
      Greg Petersen over 12 years
      To narrow down the problem, just try to move it to /tmp folder to see what happens. Are you running AppArmor?
    • Tom
      Tom over 12 years
      I tried using a init-file in /tmp but no luck. Yes, I think Ubuntu uses AppArmor.
    • Greg Petersen
      Greg Petersen over 12 years
      If so, try to stop AppArmor and see if the error go away.
    • lilezek
      lilezek over 8 years
      I have been using the foreach loop, which does not work well as it stops at the first result. A loop only stops if you explicitly tell to do so, or there are no more items to iterate over.
    • TheEvilPenguin
      TheEvilPenguin over 8 years
      The foreach loop will behave the same as any other loop in this respect. Is the problem being caught by the res != resultRecord.Title test, or is an exception being thrown? An exception not caught inside the loop will break out of any loop.
    • MethodMan
      MethodMan over 8 years
      can you explain what the value of res is and what resultRecord.Title is when you make your first iteration..? this will determine if you need a break; statement inside the foreach or not.. if worse comes to worse..then convert it to a for loop and determine what the loop count should be based on the recser size
    • razor_ray
      razor_ray over 8 years
      @TheEvilPenguin It goes through each result individually, so for example, if the first result in the search is NOT equal to the Active Document, then it will think that the document doesn't exist and hence will attempt to create the Document.
    • razor_ray
      razor_ray over 8 years
      @MethodMan res is the name of the active document and resultRecord.Title is the name of the document in the EDRMS search results. If the value for both are not equal, thats when I want the new document to be created
    • MethodMan
      MethodMan over 8 years
      @razor_ray I know that .. I am asking what is the actual value of both when you use the debugger... ...
  • razor_ray
    razor_ray over 8 years
    that is exactly what I needed Eric. Thanks for your help!