Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:37:35+00:00 2026-06-01T19:37:35+00:00

My system: Ubuntu 11.10, LAMP Stack. Issue: I run the following in terminal and

  • 0

My system: Ubuntu 11.10, LAMP Stack.

Issue:

I run the following in terminal and it does the back up correctly.

mysqldump -u root  dbBugTracker > BAK/dbw.sql

But I include it in my php code like the following and it does NOT work.

exec('/usr/bin/mysqldump -u root  dbTracker > BAK/dbT.sql');

Tips:

  • I tried putting a second parameter in exec but nothing is shown except the word Array. I print it out but nothing in it.
  • The file dbw.sql is actually created as a result of the exec function but it is 0 bytes.
  • I tried with the full path and without for mysql and the same result is seen. i.e., 0 bytes.
  • The folder BAK is within my project folder and I even gave it 777 permissions.
  • Even tried different file names and databases but the result is the same.

I appreciate any inputs on this. Thank!

MORE INFO:
I added 2>&1 to the exec line and NOW the file contains some text but NOT the DB dump. This is an error and I have no idea how to deal with this 🙁
Here’s the error

mysqldump: Got error: 1045: Access denied for user ‘root’@’localhost’ (using password: NO) when trying to connect
So this is what the output file (dbw.sql) now contains.
Once again, it works fine when I run the dump from terminal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:37:37+00:00Added an answer on June 1, 2026 at 7:37 pm

    You’re running that dump command as a different user while on the command line. You are running it as Apache (I assume) when using exec(). Try adding a password parameter to the exec command, or creating an php-specific user in your db with appropriate privileges.

    UPDATE:: As I guessed, you are not able to use the root user while executing this dump using PHP. So, create a new user.

    First, login to your database from the command line. If you are the root user, don’t bother with using -u root:

    mysql
    

    Now that you’re logged in, go ahead and create a new user for Apache to use:

    GRANT ALL ON database_name.* TO yourapacheuser@localhost IDENTIFIED BY 'yourpassword';
    

    Go ahead and logout of mysql:

    exit
    

    Next, let’s re-work your original code a bit…

    $db_user = 'newusername';
    $db_pass = 'pass';
    
    $command = "mysqldump --add-drop-table -u $db_user -p$db_pass database_name > backup.file.sql";
    $output = `$command`;
    echo "Your database has now been backed up.";
    

    Now, to execute the file, run this from the command line:

    php path/to/sqldumpfile.php
    

    Hopefully you can adapt this pseudo-code. Best of luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My system is Ubuntu 11.10. I've been following this guide somewhat: http://www.ozbotz.org/opencv-installation/ I also
I have a problem with apache2 settings (Ubuntu system). I would like to run
I am on a cloud server using ubuntu where i installed a lamp stack
I would like to disable address space layout randomization (ASLR) on my system (Ubuntu
my system is Ubuntu 10 here is my code: #!/bin/bash pid = `ps -ef
I have installed KVM on my Ubuntu system. Using vmbuilder , I setup a
I´ve got a nomral user called Teacher in my Ubuntu system and it has
I am facing a strange problem on my Ubuntu Karmic system. When I call
System: rails 3.2.3 1.9.2p320 ubuntu 12.04 32 bit I am trying to split up
I just have a system crash and reinstall Ubuntu 11.10, and my code produces

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.