Now that we have covered how to make a backup of your MySQL database, we can go over how to import the backup. To do this, you can use the
cat thebackupfile.sql | mysql -D mydatabase -u myusername -p
This command uses cat to write your database to stdout and then pipes it into mysql. You'll need to have your database created first, but you can do that with:
mysql -u myusername -p -e "create database mydatabase"
One of the worst mistakes you can make is not having a backup of your database. When something goes wrong, you will be sorry. And the thing about backing up a database is that not everyone knows how to do it. There's no simple drag and drop a copy and you're done. Since there is an extra step involved, many people just skip the whole ordeal. Then they lose all of their data when a hard drive dies.
Here's how you can make a backup of your MySQL database to keep yourself happy. A program called mysqldump comes with MySQL server, enter the command below:
mysqldump -u myusername -p -B mydatabase > thebackupfile.sql
And replace "myusername" with your database user's name, "mydatabase" with your database name and "thebackupfile.sql" with whatever you want your back to be called. Now you can copy that file somewhere on a different machine to be extra safe from catastrophic data loss.
You can check out how to import the backup, also.
One of the best things about LG's Nexus 4 is that it comes unlocked and ready to use easily on any GSM network. I've had mine for 3 months and have used 3 different carriers (and the third bowl of porridge was just right). I just activated my SIM card from Airvoice Wireless, and I thought I would document how it's done here.
First, you'll need to order a SIM card from Airvoice. Mine was a cheap $4.99 and was mailed to my house in about 4 days. Once you receive your SIM card, you'll notice that it is a normal-sized card (unless they offered you the option of a micro SIM). This means that you will need to cut the card into a smaller size to fit in the micro SIM slot in a Nexus 4. Not a huge deal, but I will tell you how to do it.
Cutting the SIM card to micro SIM size
Although it's only $5, I was a bit nervous about having to wait for another SIM card if I botched this. So I did some research. First, I tried to watch this guy's video: How to Cut a SIM Card into a MicroSIM card, but he was a rambler... to put it nicely. He did provide this nice template though, to help your cutting: Normal SIM cut to micro SIM template. Just print that off and make sure your normal-sized Airvoice SIM card lines up with the outline on it. Then you can cut most of the paper away until you are down to just a normal SIM-sized template, with the micro sim outline within it. From here, you'll want to tape the template to your card. Then you can cut away the excess SIM card material until you have the micro SIM-sized card left.
If all went well, you have a micro SIM card now. Next, use the SIM card removal tool that came with your Nexus 4 (or needle or similar sized item) to eject the SIM tray. Place the new SIM card in the tray and put it back in the phone.
Set up Airvoice Wireless APN for your Nexus 4
To set up Airvoice's cellular network on the Nexus 4, you will first need to add a plan and activate your SIM card. To do this, just go to Airvoice's site (should be here: Airvoice New Activation) and follow the directions. Once you have your phone number, you are ready to enter the correct APN settings on the Nexus 4.
To change your APN settings, go to Settings, then "More..." in the "Wireless & Networks", then click on "Mobile Networks" and "Access Point Names". From here, you can tap the three square dots in the upper right-hand corner to add a "New APN".
Airvoice's APN settings are as follows:
Name: US - Airvoice Web APN: att.mvno Proxy: Port: Username: Password: Server: MMSC: MMS Proxy: MMS Port: MMS Protocol: WAP 2.0 MCC: MNC: Authentication Type: PAP APN Type: default, supl PXT Messaging MMS: Name: US - Airvoice MMS APN: att.mvno Proxy: Port: Username: Password: Server: MMSC: http://mmsc.cingular.com MMS Proxy: 18.104.22.168 MMS Port: 80 MMS Protocol: WAP 2.0 MCC: MNC: Authentication Type: PAP APN Type: mms
Once you put those settings in, you can tap the three dots in the lower right-hand corner and select "Save". Then make sure you have your new APN selected. It should work as soon as you do that, but if it doesn't, just turn the Nexus 4 off and back on.
Many would argue that there is no command line tool to rule them all, but I disagree. There is one that will make using the command line orders of magnitude easier to use, and that is the bash shell's reverse history search. To use it, just press ctrl+r and start typing a part of any command you have used before:
(reverse-i-search)`comm': git commit -am "daily" && git push
In the example above, I have pressed ctrl+r and typed
comm. The reverse search utility has populated my line with the last command I entered that had
comm in it. This means once you have entered a command, you don't have to remember exactly what it was, but just a part of it. Then you can use reverse history search to find it.
If I wanted to use this command again as-is, I could press enter. If I want to edit the command before using it, I can use the horizontal arrow keys or the escape key to exit the history search while keeping the command ready for changing or hitting enter.
You can also press ctrl+r multiple times to continue back through your history to earlier commands containing what you the string for which you are searching.
This is the one utility that has saved me more time than any other when it comes to working with the command line.
Sometimes you end up with a storage drive mounted with read-only access in Linux. Here is how you can remount it with read and write access so that you can make changes to files on it (create new ones and delete others):
sudo mount -o remount,rw /
In this command the
-o flag is for options, the
remount option tells
mount to remount the the partition with different options and the
rw option means that it will be mounted with read and write access. The
/ part is the mount point of the partition, being the root in this example.
You can check out your mounted partitions with the
magnatecha@d64:~$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 73840300 57696476 12445444 83% / udev 2050688 4 2050684 1% /dev tmpfs 823192 908 822284 1% /run none 5120 0 5120 0% /run/lock none 2057972 4188 2053784 1% /run/shm
Vim is a powerful text editor with tons of features. However, not all of these features are immediately apparent to new users of Vim. To get started with Vim, check out my Beginner's Guide to Vim. Here's a tip for something I didn't cover in that guide, using tabs in Vim.
To use tabs with Vim, open a file in Vim, like so:
Enter that command in a terminal and Vim will open "mytestfile" and allow you to edit it. To get another tab open in that same instance of Vim, use this command from normal mode (hit Esc to make sure you're in normal mode):
That will open an unnamed document in a new tab. You can see the tabs at the top of your Vim screen. To open a specific file in a new tab, you can do something like:
That will open "myspecificfile" from the same directory as "mytestfile", you're current directory, in a new tab. Say you want to open a file from a different directory or folder, you do this, while in normal mode:
This will open "myotherfile" in the directory "adifferentdir" in your home folder (/home/youruser).
You can move to the next tab you have open by pressing "gt" in normal mode. You can move 2 tabs down by pressing "2gt".
Moving to the previous tab is not too cool in Vim, by default:
So I mapped a key combo for normal mode to move to the previous tab by pressing "gr". You can check out how I did that in my Normal Mode Shortcuts in Vim post.
One of the most powerful things about Vim is the ability to assign arbitrary key shortcuts or mappings. This allows you to make your most frequent activities into very fast mappings of just a few keystrokes. For example, I have the movement from the current tab to the previous one assigned to "gr" in normal mode.
You can do this by going to normal mode and entering
:map gr :tabp
and then pressing enter. This tells vim to enter :tabp and a carriage return whenever it sees you press "gr" in normal mode. Otherwise you would have to enter ":tabp" and press enter yourself.
Entering the shortcut in Vim like this will work, but it will only last until you close that instance of Vim. If you want the mapping to work every time you use Vim, you can save it in a file called
.vimrc in your home directory. Open this file with
and then save that shortcut in it. The next time you open Vim, it will already know about your mapping.
This is a simple normal mode mapping, but it saves keystrokes that take time. You can do all sorts of complicated mappings in normal mode and Vim's other modes. Play around and experiment to see how much you can do with just pressing a few keys.
I use Skype for Linux to talk with my coworkers all day, every day. I also use Chromium for my browser. Unfortunately Skype seems to have a problem with honoring my selection for my default web browser. Although I have Chromium selected on Ubuntu's settings panel as my default browser program, Skype opens all links with Firefox.
I eventually got tired of this and "fixed" it. I say fixed with quotes because this is not a perfect solution. Here's how to make sure Skype uses your default browser. Open a terminal and enter these commands:
sudo mv /usr/bin/firefox /usr/bin/firefox-moved
sudo ln -s /usr/bin/chromium-browser /usr/bin/firefox
Those two commands move the Firefox binary to a separate file and then link the Chromium binary to the old Firefox location. So Skype thinks it is still opening the url with Firefox, but it actually opens it with Chromium.
This isn't the best fix, and Skype should already be working correctly based on Ubuntu's settings, but it will get the job done.
I recently switched from using Sublime Text 2 to Vim. Sublime is an awesome text editor, but I enjoy using command line tools and am intrigued by the massive following that Vim has. Also, three of the developers I work with use Vim and seem to know a lot of the tricks that make Vim indispensible. Although I haven't gleaned much from them yet, I have found my way around Vim at my own pace. Here are some tips for Vim beginners.
First, you can start of by opening Vim and editing a test file. Just open a terminal and type:
This will open vim with the file
test open. The key thing with Vim, from the beginning, is that it has different "modes". We'll start with the two most often used: normal and insert mode. Vim opens in normal mode. This mode is used for moving around in a text file. And move Vim does, often cited for allowing you to move quickly around the file without touching your mouse or trackpad.
So, you're in normal mode now, after you typed
vim testvim. Without any text, there's not much need to move about. So you should switch Vim's insert mode now, by hitting your "i" key. Now the bottom of your terminal should say
-- INSERT --. This means you can insert text now. So type away, and Vim will act like your plain old text editor by dutifully placing the characters you type into your file.
Go ahead and type or paste this text so I can show you how to move around in Vim with your keyboard:
This is how we Vim. Vim, a magical editor, allows you to quickly manipulate files with deft fingers. This results in much happiness, and here are some "special" characters for fun: _-(&!
You can paste into most terminals with Shift+Control+V. Now that you have pasted some text in, you can exit Vim's insert mode and go back to normal mode by pressing the escape key. Here are a few key shortcuts for moving around the document in normal mode. Just press the key for each letter to use the shortcut:
There are many more shortcuts for normal mode like those above, but that will get you started.
Vim also has commands that can be given from normal mode using the ":" character. To use these commands, enter normal mode then type ":" and your command immediately following it:
Typing the ":w" command above and pressing enter will tell Vim to save (or "w" for write) the file you are working on. Here are a few more commands like this:
There is a ton more features in Vim (a ton, really), but I'm going to leave it here for now since this is a beginner's guide. Get out there and discover Vim's awesomness by using your favorite search engine. And check back here for updates, as I learn more about Vim myself. Oh yeah, one last Vim trick that I use a lot is pressing "o" in normal mode. This will insert a new line below the line you are on and change to insert mode for you to start typing.
Sometimes you need to find when a certain piece of code was first introduced into your code base. Perhaps you're wondering who wrote the first version of a certain function. It's pretty easy to find what you're looking for with git's log command. All you need to do is use the
-S flag with it:
git log -SmyFunction
This will return all the git commits that introduce or remove the string "myFunction". Here is git's manual entry on the flag:
-S<string> Look for differences that introduce or remove an instance of <string>. Note that this is different than the string simply appearing in diff output; see the pickaxe entry in gitdiffcore(7) for more details.
Once you have the commits that you're looking for, you can take a close look at them with
git show aae88c084c5b1c888f1e26a5b327739a3825d1df
where "aae88c084c5b1c888f1e26a5b327739a3825d1df" is the SHA of the commit you want to inspect. This will show all the files that were changed in the commit and a diff of each version, before and after the commit.