How to update data from localhost MySQL server to remote MySQL server - php

I would like to update data for every action (insert, update, delete) that happens on a localhost MySQL server to a remote MySQL server. How would I do that?

Enable database replication. It's not a great idea to flush frequently for performance reasons, but maybe it's an acceptable tradeoff?

Can't you use Triggers?
22.5.5: Is it possible for a trigger to update tables on a remote server?
Yes. A table on a remote server could
be updated using the FEDERATED storage
engine.
From : http://dev.mysql.com/doc/refman/5.0/en/faqs-triggers.html#qandaitem-22-5-1-5
I wouldn't recommend this because you will be consuming bandwidth for every small change you do. You can try a scheduled job instead.

Here is a simple and safe solution using a git server and works fine if the two db_tables don't change that much and don't have to be identical at all times.
Create a repository on your git server (GitHub, Bitbucket, other)
Clone the repository to both your servers
On the server you want to export from run those terminal commands
$ cd /my/repository/path
$ mysqldump -h localhost -u User_Id -pPassword DB_name Table_Name > Table_Name.sql
$ git add .
$ git commit -m "Table Update"
$ git push https://git_server/repository/name
The db table is now on the git server.
On the server you want to import to
$ cd /my/repository/path
$ git pull https://git_server/repository/name
$ mysql -h localhost -u User_Id -pPassword DB_name < Table_Name.sql

Related

Connect to SSH using password and Perform Some commands using shell script?

I am working on Magento 2 Project.
I did Setup Git on my server. so I can push and pull changes on server directly without using ftp.
in my local i do push changes to git. and I do pull on remote side. so I get my changes over there.
So I am thinking to create shell script that manually written command are perform one by one by just executing one script.
In Script I am thinking too.
Connect server using ssh. hosts name and password.
and then enter in project directory using cd project name.
and there it perform git pull command.
and some magento commands to update changes. (Like: bin/magento setup:upgrade etc...)
So is there any way to do something like this?
You can execute commands over ssh by doing ssh user#host 'command1;command2' and either use sshpass (but you'd have to store the password in plain text, which is a bit of a no no) or set up key-based authentication (recommended)
First, you’ll have to install sshpass, can install by running following command in your terminal:
sudo apt install sshpass
Now go to /home/{youruser}/ and open .bashrc file in any editor ( Press Ctrl+H, if file not visible ).
Now let’s create a command alias, create a new line in .bashrc file as per your project details. For example:
alias connect-magentto=’sshpass -p “your ssh password here” ssh yourusername#yourhostname’
Copy-paste above command in .bashrc file and save it and open a new terminal. Enter “connect-magento” in the terminal and now you’ll connect to the server without a copy, pasting, or typing anything.
Similarly, you can make shortcut of other commands whichever you wish to by adding in .bashrc file and giving it an alias.

phpMyAdmin is showing blank page while trying to export a database?

Recently I uninstalled the Wamp Server and re-installed the newer version of Wamp Server which is 3.1.3
Note: I am using Windows 10
Below are all the details of Wamp Server:
Apache Version: 2.4.33
PHP Version: 5.6.35
MySQL Version: 5.7.21
phpMyAdmin Version: 4.7.9
When I click on MYSQL Database in phpMyAdmin and then click on Export, the phpMyAdmin shows blank page. However, when I click on Import, phpMyAdmin doesn't show blank page at all. But the strange thing is when clicking on Export, phpMyAdmin shows Blank Page.
Since, I'm trying to export a Database from phpMyAdmin, I need to make sure that the page doesn't go blank when clicking on "Export" button.
I'm not sure regarding how to approach this problem because I'm very new in phpMyAdmin.
Would be really helpful if any recommended advice or solution is provided.
If you want to export the database using Command Line, then in that case, you can use mysqldump command.
If it's an entire DB, then:
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
If it's all DBs, then:
$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql
If it's specific tables within a DB, then:
$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql
You can even go as far as auto-compressing the output using gzip (if your DB is very big):
$ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz
uname - Username of database
pass - Password of database
You can check this answer
If you are using Windows then you need to change directory to C:\wamp\bin\mysql\mysql-version\bin and do above steps.
If you're using Ubuntu.
That problem caused by, you have not installed libapache2-mod-php.
So, install with :
$ sudo apt install php libapache2-mod-php
then restart apache
$ sudo service apache2 restart

Httpd, myslqd and SELinux

Im running put of patient with SELinux and that stuff...
I have httpd and myslqd running on the same machine with CentOs 6, and both services have their configuration files in a nfs directory exported from another machine.
Everything works fine with Selinux disabled... but when I set it to enforcing, PHP scripts can not communicate with mysql service. Httpd service works fine and mysqld too, if I run "mysql -u root" I can make queries to the database perfectly, but php scripts can not.
I think I'm missing some sebool that allows php to use mysql or something like that, but i can not find the key... some help?
You can set the following flag to allow Apache to connect to a database.
setsebool -P httpd_can_network_connect_db on
The -P option makes the change persist across reboots. You may need sudo to execute this command.

Envoy and Mysql

I'm making a SSH Task with Envoy and Laravel, the problem is that when I make something like
#task('truncate', ['on' => 'remote'])
echo 'Truncating table...'
mysql --help
#endtask
It outputs
mysql: command not found
And yes... I have mysql installed on remote server. If I manually ssh into it and write mysql it works as expected.
I found the solution. In remote server I'm using Zsh and Envoy is using Bash, thats why mysql isnt been loaded with PATH.

Installed XAMPP but can't connect to MYSQL server in cmd

First, MYSQL services is running in XAMPP
and, YES, I changed the port since it conflicts with other applications
Now, the question is why can't i connect to MYSQL?
Error 2003: Cant connect to MYSQL server on 'localhost'
I also dont have any mysql services installed.
Please help. Thank you for those people who would answer me :)
First,make sure mysqld is running.
ps -ef |grep mysql
Second,get the socket file in the output of last command:
for example:--socket=/opt/lampp/var/mysql/mysql.sock
Then,try to connect to mysql:
mysql -uroot -p -P<port> -hlocalhost -S /opt/lampp/var/mysql/mysql.sock
option 1.
Goto /bin/
Run mysqld (service)
close the cmd prompt
Run mysql.exe (make sure you add the location path to PATH environment Variable)
Option 2.
try to follow this thread and see if it can help!!
http://forums.devshed.com/mysql-help-4/error-2003-cant-connect-mysql-server-localhost-10061-a-26423.html
Run mysql.exe (make sure you add the location path to PATH environment Variable)
I would to know where is PATH enviroment variable

Categories