Yes, no problem. Use BCP (which is a command line tool) to export the data. Once you have the parameters the way you like, schedule this as a SQL Agent job.
If you are able to shut your database server down (and my understanding is that you are indeed able to) - thereby disabling your application - then that's the easiest indeed.
You can, after shutdown, just copy+paste your data directory. Where is your data in the first place? Just issue:
SELECT @@datadir;
From within your MySQL server.
By the way, while you must backup your data someplace safe, I do not expect any of the apt-get
or aptitude
commands to actually touch your data.
NOTE that the page you've linked to has some pretty crazy ideas, like:
[!!DO NOT DO THIS!!] find / -iname ‘mysql*’ -exec rm -rf {} \;
I encourage you to look someplace else, given the above query. It will remove any and all mysql* file from your root filesystem. Including your own application's mysql-config.ini
files (if any, of course), including libdbd-perl-mysql
-- without clean uninstall... I mean, this is really BAD advice.
There's no point in backing up your my.cnf
file, delete the file then put it back again. The same holds for your datadir
.
Just uninstall MySQL and re-install is enough -- but that, too, is kinda funny, since both are done via apt-get
-- so you basically reinstall the same version... At least get yourself newer version of MySQL.
Best Answer
While this is not a good choice for actual backups, there are some use cases for dumping tables to text files. In that context, an alternative approach to using
xp_cmdshell
to call BCP.EXE is to use the DB_BulkExport SQLCLR Stored Procedure that is available in SQL# (which I wrote). You can then use File_GZip to compress the files.The following are advantages and disadvantages to using DB_BulkExport compared to BCP.EXE:
Pros:
xp_cmdshell
BIT
representation: 1 / 0, T / F, or True / False.SMALLDATETIME
,DATETIME
,DATE
,TIME
,DATETIME2
, andDATETIMEOFFSET
format.Cons:
Please note that DB_BulkExport only exports data; it does not record the structure of the result set. This is no different than BCP, nor is it really any different than the solution provided in the main community wiki answer given that the solution there ignores collations, computed columns, most column options, etc.
Another option for SQL Server, mentioned by Kin, is mssql-scripter. This is a free / open source, multi-platform, Python-based tool. I have not used it, but it seems to export DDL and/or DML statements that can be executed to recreate the data and/or schema (tables, constraints, etc). It appears to only export the data as
INSERT
statements instead of as delimited fields. Looks quite interesting, but please review the "Issues" to make sure that there isn't anything that would impact your usage.Also, even though this question (and the main community wiki answer) mention SQL Server, the issues surrounding GDPR are not specific to SQL Server. So, just thought I would mention that the ability to export tables (and even schema, etc) is available for MySQL in the following two utilities that come with it:
The same can be done in PostgreSQL using the following two utilities that come with it:
For Oracle, please see the following resources, which I believe will at least get you very close, if not fully equivalent output (thanks to Michael Kutz for pointing me in the right direction):
I'm not sure if similar utilities come with DB2.