exporting mysql table with bulk data in phpmyadmin - mysql

I have a mysql table with large amount of data. I need to export this table to another database with all the data. But when I try to export the table as sql file from phpmyadmin, it shows error
The webpage at https://i.p.adress/domains/databases/phpMyAdmin/export.php might be temporarily down or it may have moved permanently to a new web address.
I tried exporting as CSV also, but the same error happens.
Does it happens because my table contains large amount of data? Is there any other way to export this table with all data?
I have around 1346641 records.

Does export work with a smaller database? Does it process for some time before showing that error or is it displayed as soon as you confirm your export options? I don't recall having seen that error message relating to large exports, but I may be remembering incorrectly. Any hints in your webserver or PHP error logs? Which phpMyAdmin version are you using?
Regarding large exports:
Because of the nature of phpMyAdmin running as a PHP script on your server, as well as sending the downloaded file to you as a download, there are a number of limitations forced on it. Web servers are usually configured to keep PHP programs from running for very long, and a long download (or long time processing the export) can be affected. Additionally, memory and other resources are often limited in a similar manner. Therefore, it's usually better to use some other means of exporting large databases.
The command-line utility mysqldump, provided with the MySQL server package, is the definitive standard. If you have command line/shell access, it's best to use mysqldump to export the .sql file(s) and then copy those through any normal file-transfer protocol (FTP, SCP, SSH, etc).
That being said, phpMyAdmin has several enhancements and tweaks that can make this possible.
Use $cfg[SaveDir] to enable writing the exported file to disk on the server, which you can then copy through any normal file transfer protocol.
If you encounter timeouts or resource restrictions, you can edit the PHP configuration directives (the linked documentation refers to imports but the same restrictions apply to exports).
Experiment with the export compression setting, in particular using an uncompressed export format (exporting to SQL directly rather than a zipped archive) can work around some memory restrictions.

Related

Sending .csv files to a database: MariaDB

I will preface this by saying I am very new to databases. I am working on a project for my undergraduate research that requires various sensor data to be send from a Raspberry Pi via the internet to a database. I am using MariaDB at the moment, but am open to other options.
The background: Currently all sensor data is being saved in csv files on the RPi. There will be automation to send data at given intervals to the database.
The question: Am I able to audit the file itself to a database? For our application, a csv file is the most logical data storage format and we simply want the database to be a way for us to retrieve data remotely, since the system will be installed miles away from where we work.
I have read about "LOAD DATA INFILE" on this website, but am unsure how it applies to this database. Would JSON be at all applicable for this? I am willing to learn if it makes the process more streamlined.
Thank you!
If 'sending data to the database' means that, by one means or another, additional or replacement CSV files are saved on disk, in a location accessible to a MariaDB client program, then you can load these into the database using the "mysql" command-line client and an appropriate script of SQL commands. That script very likely will make use of the LOAD DATA LOCAL INFILE command.
The "mysql" program may be launched in a variety of ways: 1) spawned by the process that receives the uploaded file; 2) launched by a cron job (Task Scheduler on Windows) that runs periodically to check for new or changed CSV files; of 3) launched by a daemon that continually monitors the disk for new or changed CSV files.
A CSV is typically human readable. I would work with that first before worrying about using JSON. Unless the CSVs are huge, you could probably open them up in a simple text editor to read their contents to get an idea of what the data looks like.
I'm not sure of your environment (feel free to elaborate), but you could just use whatever web services you have to read in the CSV directly and inject the data into your database.
You say that data is being sent using automation. How is it communicating to your web service?
What is your web service? (Is it php?)
Where is the database being hosted? (Is it in the same webservice?)

Explore database contents from .sql file

I inherited the maintenance of a small web forum. Near as I can tell, it is powered by a MySQL database on the backend (the frontend is all PHP).
I need to extract some of the data (which also involves searching for the data I need to extract), but I don't want to touch the production database. I exported a database backup, which produced a several-hundred-megabyte .sql file.
What's the best way to mine these data? I can see several options:
grep through the .sql script in text mode, trying to extract the relevant data
Load it up in sqlite3 (I tried doing this, but it barfed on some of the statements in the script and didn't produce any tables. I have no database experience whatsoever though, so I haven't ruled it out as a dead end just yet).
Install MySQL on my home box, create a database, and execute the .sql script to recreate the data. Then just attach some database explorer tool.
Find some (Linux) app which can understand the .sql file natively (seems unlikely after a bit of Googling).
Any pointers to which of these options (or one I haven't thought of yet) would be the most productive?
I would say any option might work but for data mining, you definitely want to load it up in a new database so you can start query-ing the data and building reports on the data. I would load it up on your Home box. No need to have it remote.

How does the phpMyAdmin export feature work?

If I were to want to create a PHP function that does the same thing as the Export tab in phpMyAdmin, how could I do it? I don't know if there is a MySQL function that does this or if phpMyAdmin just builds the export file (in SQL that is) manually. Without shell access. Just using PHP.
I tried the documentation for mysqldump, but that seemed to require using the shell. I'm not quite sure what that even is -- maybe my question is: how do you use shell?
My silly idea is to allow non-technical users to build a site on one server (say a localhost) using MySQL then export the site, database and all, to another server (eg. a remote server).
I think I'm pretty clear on the Import process.
You can check the phpMyAdmin source code (an advantage of open-source software). Check the export.php script and the supporting functions in the libraries/export/sql.php script file.
In summary, what phpMyAdmin does is:
get a list of the tables in the given database (SHOW TABLES FROM...),
get the create query for each table (SHOW CREATE TABLE...),
parse it and extract column definitions from it,
get all data (SELECT * FROM...)
build a query according to column data.
I've written similar code for my own apps (for backup purposes, when the GPL license of phpMyAdmin doesn't allow me to use it), however I use DESCRIBE to get column definitions. I think they rather parse the SHOW CREATE TABLE output because contains more information than DESCRIBE output.
This way to generate SQL sentences requires a bit of care to handle the escaping but it allows for some flexibility, as you can convert types, filter or sanitize data, etc. It is also a lot slower than using a tool like mysqldump and you should take care of not consuming all available memory (write soon, write often, don't keep everything in memory).
If you will implement a migration process (from server to server) maybe it would be easier to do it with some shell scripting and calling mysqldump directly, unless you will do everything with PHP.

MySQL database manipulation program for Windows? Like MS Access or MS SQL?

Is there any program (preferably official) for Windows that can be used to manipulate MySQL data dumps?
For example, easily importing a MySQL text dump and create the database for all kinds of manipulations (you know, common data operations such as select, update, insert, delete, export into CSV, etc.) via a GUI interface. Much like what you can do with MS Excel and MS Access.
I know only phpMyAdmin which requires a local web server environment which might a little too much for what I need.
I thought http://dev.mysql.com/downloads/mysql/ was what I needed and installed to find out that it's not.
Any such tools exist? I ask this is actually because these MySQL dumps are for my users who know nothing about SQL or anything technical. This is for them, not me. After they downloaded the SQL I provided, they ask me: "How can I open it?"
I tried to provide them CSV, but CSV generated by this approach: http://www.kavoir.com/2010/11/mysql-export-table-to-csv-text-files-for-excel.html would contain stuff like \" if the original data contains ". When you open the CSV in Excel, \" are all over the place.
http://www.webyog.com/en/
I used to use SQLyog at my last job. It's a pretty decent GUI tool for interacting with MySQL, either local or remote. It'll cost you $99 at the cheapest, but you can try it for 30 days. If you like it and it makes life easier, it could be worth the $99, as well.
Running a local server is actually pretty easy. I use xampp which was really easy to install and came set up and ready to use phpMyAdmin. It's also really easy to shut the whole server (or just parts of it) down when it's not in use to conserve system resources.

if we only have access to phpMyAdmin what's the best way to backup the entire db?

For someone that is not used to mySQL, when using phpMyAdmin administration program, what is the recommended setup to backup the entire database with all tables and with data?
Most of those options are fine, but check the Structure -> "Add DROP TABLE..." and "Add CREATE PROCEDURE", then Data -> "Extended inserts" (this decreases loading time when re-inserting the data and isn't essential). Then click "Save as file" and export, the rest of the options are suitable.
I'm assuming that your database is large and you're having problems with phpMyAdmin timing out. If that's the case, and you don't have shell access, then you may have to write a PHP script, which executes a mysqldump command, and then call it asynchronously so there is no browser timeout issue. It would be a sloppy workaround, but if the access is limited, something like that may be your only option.
Although it has it's places, phpmyadmin's strong suit is not database backups.
Having said that, if your database is small, using the default settings via an .sql export should be fine.
If your database is large (i.e. more than a couple MB) and/or you care about it, backups should be done on the server level via logical copy, or by doing a mysqldump.