Creating procedures, using putty.exe - php

I am doing an mysql php application and I need to create a procedure to make my foreign keys work fine and also to create a calendar for report purposes. However, I have been trying to create the procedures and it does not works in putty.exe which is the only software available to do my application. I researched and I did not find anything related to this. Can anyone advise if I will need extra files for putty or the way to do it?

You need to use the mysql client to run commands against mysql. In the putty command line just run:
mysql
You will most likely need to add parameters to the command, like the user and the password needed to connect. Check the MySQL manual for details.
To run the script file that contains your procedure, first you have to upload the file to the server and then run it with
mysql < script.sql

Related

Find a script that uses MySQL database

I am editing a system which was built by another programmer at my company.
System is made using PHP and uses Send Grid for mail delivery. I just add email addresess for sending mails and all works well, but I can't find the script that writes incoming mails to database, so I can't retrieve new incoming e-mails.
Is there a way to determine which script writes to the database?
First you need to know which database engine is used, for a MySQL database search your code, for example with netbeans "Find in project", with the keywords: mysql_ or mysqli.
Other classes used for database access are PDO and ODBC, for that you should search after PDO or odbc_.
PDO Manual
ODBC Manual
There's possibly no "standard" way to do this. I would suggest the following: Open the whole thing in an IDE (like Netbeans for PHP) if you haven't already and then do a file search for e. g. the name of the table that is concerned. Or for commands starting with mysql / mysqli, if you don't know.
If the project is running in Linux, you could also try
cd /path/to/project/sources
find | xargs grep mysql
(Replace mysql with mysqli or the table name.)
Another approch would be to force an error: Cut the database connection or rename the table(s) or something like this. PHP will throw an error that would hopefully occur in your logfiles, stating where it occured (PHP script and line).
Turn on the mysql general log and figure out which queries are coming from the input script, then you can determine the incoming IP for those queries. Watch the processlist for the incoming queries and then do a netstat -anp on the remote IP to track down which process is generating those queries.

Php Copy database to a duplicate using cpanel xaml API or something similar

I have two databases for my website. One I run my live website and the other I run a development website. My need is to copy the live database to dev database everyday.
Is there some xml API to achieve this, which will copy my database to another whichever name I want and then rename it further according to my needs.
I have to achieve this entirely using php (No Phpmyadmin interface).
I tried BigDump.php but since my database size is more than 100MB the script breaks.
For this task, I will suggest you please setup cron through cPanel and use mysqldump command for the backup and restart that with mysql command.
You can create simple bash script for this task and setup that script in cron with everyday setting

CodeIgniter: Executing database script at the startup of application

I have just started using CodeIgniter for my PHP application. I need some help regarding database creation. Instead of creating database manually is it possible that when CI application in installed on any server then after starting the apache server, my application should execute some db script file to create DB structure if the DB is empty otherwise skip the DB creation. So every time when the apache server is started or restarted, my CI application should execute this script and check whether the database structure is up to date or not and create it if does not exist or not up to date.
This way I want to make sure that after first install or everytime the application runs the DB is created and ready to use.
Hope I have explained my requirement clearly. Please let me know if any kind of configuration will help me here.

Loading lots of data into MySQL without SSH access?

I wanted to connect to my server via ssh and run a php script to enter some data into the MySQL databases.
I couldn't do this because I didn't have ssh access.
So instead I'm just going to put a php script into one of my web pages and then put the data in the same folder and then run the php by loading the browser
this seems like a really wierd way to enter data into a database?
but is it ok?
Using a PHP script to execute an SQL script should not be a problem (but be sure to delete both afterwards, just so you don't leave an unvalidated/regulated passage into your database out there).
If your webhost provides a MySQL Admin interface (often phpMyAdmin), you should be able to access that through their Control Panel (often called "cPanel" or "Plesk"). You should be able to upload and execute an SQL file through that interface without installing anything else.
Failing that, you should be able to install Adminer, which is a cutdown version of phpMyAdmin which you can then upload to your server and access through a web browser to, again, upload or copy-and-paste your SQL script into.
So you are basically rebuilding phpMyAdmin's behaviour. I would just install phpMyAdmin, but if your php script is protected (.htaccess or similar), then this should be no problem. Look out for timeouts.
A good tool for working with MySQL db is Workbench, but you must have remote access to your db...

How to download a live MySQL db into a local test db on demand, without SSH?

I have a fairly small MySQL database (a Textpattern install) on a server that I do not have SSH access to (I have FTP access only). I need to regularly download the live database to my local dev server on demand; i.e., I would like to either run a script and/or have a cron job running. What are some good ways of doing this?
Some points to note:
Live server is running Linux, Apache 2.2, PHP 5.2 and MySQL 4.1
Local server is running the same (so using PHP is an option), but the OS is Windows
Local server has Ruby on it (so using Ruby is a valid option)
The live MySQL db can accept remote connections from different IPs
I cannot enable replication on the remote server
Update: I've accepted BlaM's answer; it is beautifully simple. Can't believe I didn't think of that. There was one problem, though: I wanted to automate the process, but the proposed solution prompts the user for a password. Here is a slightly modified version of the mysqldump command that passes in the password:
mysqldump -u USER --password=MYPASSWORD DATABASE_TO_DUMP -h HOST > backup.sql
Since you can access your database remotely, you can use mysqldump from your windows machine to fetch the remote database. From commandline:
cd "into mysql directory"
mysqldump -u USERNAME -p -h YOUR_HOST_IP DATABASE_TO_MIRROR >c:\backup\database.sql
The program will ask you for the database password and then generate a file c:\backup\database.sql that you can run on your windows machine to insert the data.
With a small database that should be fairly fast.
Here's what I use. This dumps the database from the live server while uploads it to the local server.
mysqldump -hlive_server_addresss -ulive_server_user -plive_server_password --opt --compress live_server_db | mysql -ulocal_server_user -plocal_server_password local_server_db
You can run this from a bat file. You can ever use a scheduled task.
Is MySQL replication an option? You could even turn it on and off if you didn't want it constantly replicating.
This was a good article on replication.
I would create a (Ruby) script to do a SELECT * FROM ... on all the databases on the server and then do a DROP DATABASE ... followed by a series of new INSERTs on the local copy. You can do a SHOW DATABASES query to list the databases dynamically. Now, this assumes that the table structure doesn't change, but if you want to support table changes also you could add a SHOW CREATE TABLE ... query and a corresponding CREATE TABLE statement for each table in each database. To get a list of all the tables in a database you do a SHOW TABLES query.
Once you have the script you can set it up as a scheduled job to run as often as you need.
#Mark Biek
Is MySQL replication an option? You could even turn it on and off if you didn't want it constantly replicating.
Thanks for the suggestion, but I cannot enable replication on the server. It is a shared server with very little room for maneuver. I've updated the question to note this.
Depending on how often you need to copy down live data and how quickly you need to do it, installing phpMyAdmin on both machines might be an option. You can export and import DBs, but you'd have to do it manually. If it's a small DB (and it sounds like it is), and you don't need live data copied over too often, it might work well for what you need.

Categories