The attached script can be used to migrate data out of a sqldump and into csv and xls for further analysis or ETL’ing. The name of each table is used to create a separate csv file (e.g. table1.csv) and an xls representation of each table is put into a workbook in a spreadsheet.
The script requires Python 3.7. So if you’re on a Mac you might need to install that. Here, we use Homebrew to do so:
brew install python3
Then you’d need to install the specific mods:
python3 -m pip install pandas
python3 -m pip install openpyxl
The command is then run as follows:
python3 sqlcsvxlsexport.py <sql dump file> <target directory>
The script is accessible here:
OS X might be the easiest platform to install MySQL on. To do so, simply download the MySQL installation package from the MySQL Download site. I like to use the third link (the DMG).
Once downloaded, run the package. The package will ask you a few questions and you can easily just select the default choice during the installation process.
Once installed, you’ll be prompted that a temporary password has been used for your MySQL instance.
The password will get you in the first time, so you can change it. Once you have documented the password, open System Preferences and click on MySQL in the bottom row of System Preference Panes.
Click Start MySQL Server and then when prompted, authenticate to the system. If you’d like to do this programmatically and don’t need the System Preference pane, you can do so with homebrew. If you have homebrew installed, simply run the brew command with the install verb and mysql as the package:
brew install mysql
Whichever way you install SQL, once installed, you’ll want to set the root password to something other than the intuitionally difficult to remember password provided at install time. To do so, first connect to the mysql instance now running on your computer. As the tools are installed in /usr/local/mysql/bin, run the following:
/usr/local/mysql/bin/mysql -u root
Then, set the password using the ALTER statement along with the USER option and then the username followed by IDENTIFIED BY and ultimately the password, as follows:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysupersecretpassword';
Once done, you’ll then be able to connect to mysql normally.
Xcode and other tools can be used to view logs on iOS devices. One of those other tools is libimobiledevice
. I usually install libimobiledevice using homebrew, as there are a few dependencies that can be a little annoying. To install homebrew if you haven’t already, run the following command:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Once run, follow the prompts to complete the installation. Once homebrew is installed, run the following brew command to download the required components and then libimobiledevice:
brew install -v --devel --fresh automake autoconf libtool wget libimobiledevice
Then run ideviceinstaller:
brew install -v --HEAD --fresh --build-from-source ideviceinstaller
Once these are installed, you can plug in a paired device, unlock it and use the following command to view the logs on the screen:
This is akin to running a tail against the device. Again, the device must be paired. You can use the command line (e.g. if you’re running this on Linux) to view the logs, but if you’re not paired you’ll need to use idevicepair to pair your device, followed by the pair verb (which is very different from the pear verb):
You can also unpair using the unpair verb:
When pairing and unpairing, you should see the appropriate entries in /var/db/lockdown. The final option I’m going to cover in this article is the date (very useful when scripting unit tests using this suite. To obtain this, use the idevicedate command, no operators or verbs required:
The Terminal application defaults have a problem passing colors with Ubuntu and other types of Linux machines with properly formed .bashrc files. This is because those systems do not know how to interpret the Lion xterm-color256 terminal declaration.
The fix is to change this setting to xterm-color. This needs to be done for each Terminal default. Click on each (Basic, Grass, Homebrew, etc) and then click on the Advanced tab. From there, just set the Declare terminal as: to xterm-color and close.
This can also be done through the command line. These settings are stored in the com.apple.Terminal.plist per user, in their ~/Library/Preferences. The key for each is in TerminalType, which should read:
TerminalType = "xterm-color";
This small issue pales in comparison (especially because it is easily remedied) to how great the ability to take Terminal into full screen mode, have it state fully open and show the last run commands, assign background images and other little cool tricks are. There are also lots of new commands in Lion, such as tmutil
that you’re sure to love if you haven’t made the upgrade yet!
I originally posted this at http://www.318.com/TechJournal
Apple has been slowly winning over a lot of traditional Unix and Linux converts. This new breed of switcher is after a cool shell environment. In Leopard, Apple has upgraded Terminal.app to provide a whole slew of new features that are sure to continue winning new converts. Letâ€™s just take a look at a few of them:
Secure Keyboard Entry – Prevent other applications from detecting keystrokes used in terminal. Enable this using the Terminal menu.
Tabbed Interface – I always have 3 shell windows open. Thatâ€™s how I roll. But with the new tabbed interface (which you can access using the Command-T keystroke) I find that Iâ€™m using two shell windows with 3 tabs each. This gives me the ability to have a man page or process list on one side of my screen while being able to run other commands on the other side. You can fire up 2 shell windows and then open as many tabs as you like.
Export Settings – This isnâ€™t new in Leopard, but what is new in Leopard is that the tabs get exported along with window positions, layouts, themes and backgrounds.
Themes – Glass, Homebrew, Novel, Red Sands – these themes allow you to use prebuilt templates for how you view your shell. These include background, text color, transparency. Can you imagine Steve sitting in his office at Apple dinking around with the Homebrew theme?
Window Groups – A group of windows with a saved location, tabbed layout, shell configuration and settings.
Terminal Inspector – Switch themes on the fly, view running process and increase the columns and rows of a shell environment.
Titles – Set titles for your terminal windows so you can remember what was where.