If you ever need to copy a large amount of data over a network (especially if its a huge number of small files) you can pipe a tar command through a ssh connection, and because tar copies whole blocks at a time, it will be far, far, faster than using SCP.
To execute it, simply:
$ tar czf - <files> | ssh user@host "cd /wherever; tar xvzf -"
I recently had to import a 30GB MySQL database from a backup of a client’s production database. My development workstation really struggled with the hundred’s of thousands of INSERT queries, and the import either took an unacceptably long time or failed outright.
Fortunately, there is a sure-fire way to increase the import though (in my case a 100 fold increase in speed).
Simply open Terminal and type:
> mysql -uXXX -pXXX
…and replace the X’s with an appropriate username and password and then paste this at the MySQL prompt:
CREATE DATABASE my_database;
set global net_buffer_length=1000000;
set global max_allowed_packet=1000000000;
A few notes: ‘set global net_buffer_length’ and ‘set global max_allowed_packet’ only apply if your source filename and path are over a network. Also simply omit the ‘CREATE DATABASE my_database;’ line if you already imported the blank schema, or the database already exists.
Previously I have mentioned an awesome little command-line tool called ‘pv’. Recently, I was trying to restore a clients of legacy database on my development machine, which was a staggering 30GB .sql file. I was having quite a few problems trying to wrestle this beast, the worst of which being that I had no idea how much longer the import would take, or if it had locked up. Luckily, PV comes to the rescue.
Normally, when importing a MySQL dump file, you can just type:
mysql -uxxx -pxxx dbname < /sqlfile.sql
…to import directly from the file. However, you can pv the file and pipe it into the mysql executable like:
pv sqlfile.sql | mysql -uxxx -pxxxx dbname
And you will get an awesome progress bar about how completed the task is. You can also use it in the reverse. You’d be surprised how useful it can be.
I recently had some database woes. I needed to restore a MySQL database of a clients existing website that was dozens of gigabytes in size. I had a great deal of trouble trying to import that data, but that’s a story for another time. This was about getting MySQL installed in the first place (for a development environment).
At first, I tried using Homebrew – because its awesome and I like it. But sadly, for one reason or another the default configuration just wasn’t working for me. It was simple and blind, but too well hidden and I didn’t feel like there was enough “control” (like getting setting/getting the default root password for example). If you’re going to automate something, then automate it – but don’t ask me to run stuff to secure my install when your supposed to be automating it for me. Bah humbug!
However, the wonderful folks at macminivault.com solved all my problems. It was simply perfection. Exactly the right balance of automation and control.
Just open up Terminal and paste this into it:
bash <(curl -Ls http://git.io/eUx7rg)
It will tell you or prompt you for the rest. And don’t forget to get the text file containing the root password, before you mistakenly delete it.
(comic property of http://www.brainstuck.com/)
Installing Ruby with RVM on Mac is a cinch, simply execute:
\curl -sSL https://get.rvm.io | bash -s stable --ruby
But recently, while trying to install RVM instead of the default Mavericks Ruby, the script that normally just “works” fails with the ominous message:
: Requirements installation failed with status: 1.
It turns out to be something funky with Mavericks and the Homebrew step of the installation. Luckily, despite the failure of the script, you can simply install Hombrew manually to solve the problem. Installing Homebrew is a triviality, simply execute the following command in Terminal:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
It will first install the XCode Command Line Tools (don’t worry if you already have it, just hit “install” and let it do it’s thing) and then once the Xcode dialog disappears, hit [any] key in Terminal and it will auto-download and auto-install itself. Once its all finished (and it can take a few minutes, just be patient), simply re-execute the command to install RVM Ruby.
Just like when using Windows, sometimes it is necessary to make special hidden system files visible to Finder. There is no preference for it, but with a simple Terminal command, things can be made visible very easily, on a privileged user account.
Simply open the ‘Terminal’ application, and at the prompt, type:
defaults write com.apple.finder AppleShowAllFiles TRUE
This will cause all Finder windows to close and then reopen with the hidden files, visible and identifiable with a ghost-like appearance. You should be able to interact with them normally now.
Forget what I said. Install Homebrew (really, do it now) and use HomeBrew to install it.
Pipe Viewer (pv) – is a terminal-based tool for monitoring the progress of data through a pipeline. It can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion. However, it isn’t included by default in Mac OSX.
The good news is that there are several ports of pv, you just need to go and grab one:
- HomeBrew: Run “
brew install pv” to get the latest version.
- MacPorts: Run “
port install pv” to get the latest version.
- Or (recommended) install the Rudix pv port (a simple package installer)
Pv allows you to get a really awesome progress of your terminal commands to see how things are going; especially useful for long operations (such as cp or tar etc) so you know everything is ticking over time (and perhaps even giving an ETA for completion):
13.2GiB 1:33:17 [3.57MiB/s] [================================> ] 67% ETA 0:44:4
I highly recommend this for anyone doing long, large or complicated terminal commands. It’s outstanding! To learn more about using Pipe Viewer, this is a great resource.
It’s no secret that I adore my Mac, mostly because it just makes my life easier. I enjoy the security of OSX, I love it’s responsiveness and I love that my operating system doesn’t punish me for installing applications and development stacks just to ‘play with them’. A while ago, while looking for a stack that would let me quickly and effortlessly get Apache, MySQL and PHP5 working together without having to muss about with configs and the such, I discovered MAMP and frankly, I adored it instantly. After a rather large download, it was effortless to install and running it was a cinch. And better still, the server applications only run when you open the MAMP application and tell them to run, so that you dont loose vital system resources running services you dont need.
Additionally, my IDE of choice, NetBeans can integrate directly with MAMP, so that when you create (for sake of argument) a new PHP project and run it, it automatically puts the project files into the MAMP Apache directory (to be honest you do need to configure the path when you create the project, but its no big deal) making development painless and convenient.
But I did hit a snag recently when for a university assignment I was required to do a XHTML website using HTML Server Side Includes. I was shocked when I ran my website and my SSI didnt work.
But there is a solution.
To make .shtml work, I deleted the comment-symbols ( # ) in the file http.conf (find it in /Applications/MAMP/conf/apache/ and at the time of writing was near lines 982:
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml