skip to Main Content

On laravel 10 site I need in admin area to show some info on mysql database, which is used in mysql db replication.

When I need to get mysql status I run command under mysql console :

SHOW MASTER STATUS G

But with symfony/process library I can get and show output of linux commands, but not a command which I run under mysql console.
I searched in mysql-mariadb section of the documentation :
https://docs.platform.sh/guides/symfony/environment-variables.html?utm_source=symfony-cloud-sign-up&utm_medium=backlink&utm_campaign=Symfony-Cloud-sign-up&utm_content=docs#mysql-mariadb
But I did not find any hints how to get output of the command.

How this can b3e domn? Some other tools ?

"laravel/framework": "^10.35.0",
"symfony/process": "^6.4",

Thanks in advance!

2

Answers


  1. You can run a CLI command to connect to MySQL and run the script you wanted:

    mysql -h yourroot -u youruser -pyourpassword -e "yourscript;"
    

    Of course, you will need to replace:

    • yourroot
    • youruser
    • yourpassword
    • yourscript

    with appropriate values.

    Login or Signup to reply.
  2. You can run this using DB facades , handle the result and show in your view

    
    
    //in your route 
    
    
    Route::get('/admin/mysql-status', 'AdminController@mysqlStatus');
    
    
    // in your Controller  
    
    $status  = DB::select(DB::raw('SHOW MASTER STATUS'));
    
    
    return view('admin.mysql_status', ['status' => $status]);
    
    
    
    // in your view  
    
    @foreach ($status as $row)
        <p>{{ $row->YourColumnName }}</p>
    @endforeach
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search