You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialize correctly.

Lazy Access to Command Line MySQL

 
 

I’m a Command Line type of guy. I don’t appreciate have to move my hand back and forth to a mouse to get something done. 

There are some great GUI based MySQL tools out there and probably my favorite is Sequel Pro on the Mac... But that isn’t the point of this blog today.

There are many times that I am at the Command Line and need to get something done. Being lazy (see title) and not using MySQL command line tools every day, I built a script to handle some defaults and remind me of some options.

I called the script (written in Bash) simplesql. This has been published on github for your access and enjoyment.

Some of the features of this script are as follows:

* An optional configuration file where I can store server name and aliases, along with usernames, passwords, and default database names.

* a quick access CLI mode “simplesql -o sql02”. This command uses the alias ‘sql02’ to lookup the servername, gets the user/passwd from the config file, and without other instructions, goes into edit mode. Behind the scenes this basically launhes “mysql -u b3sql02.domain.com -u root -ppassword” and I am in MySQL ready to do some adhoc Command Line work.

* a Dump, Import, Copy, Clone, & Export set of commands. Export will output CSV formatting for a table.

* run a ‘top’ like program to provide statistics for a particular server.

* A couple of Drupal specific commands. One is a dump without the watchdog, session, & cache data. The other is a mass updated to change the admin password

Security is a big issue and some of the features of this script are more geared for a smaller or mid-sized environment. I have left those features in the script as they were very useful to us until our growth demanded a higher focus on security. Today we do not use the external storage of password in the config file. That was a policy change but the feature should still work. Another security issue is that early on, we would have a common ‘admin’ password. So, the alter command came in very useful to do mass changes to that password with personnel turnover. Use it at your own risk  

 

Well, that is about it.... It has save me a lot of time and trips to the man pages over the years. I hope you might find it useful too.

 
The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • HTML tags will be transformed to conform to HTML standards.

More information about formatting options

 

If you are running a drupal

If you are running a drupal site, drush provides some great commands for db access.

sql-cli: Open a SQL command-line interface using Drupal's credentials.
sql-conf: Print database connection details using print_r().
sql-connect: A string for connecting to the DB.
sql-dump: Exports the Drupal DB as SQL using mysqldump.
sql-query: Execute a query against the site database.
sql-sync: Copy source database to target database using rsync.

I would also recommand Drush

I would also recommand Drush for this kind of Drupal-related database maintenance. If not only for the fact that it reads the settings.php instead of using a custom config file where users can store any password (like the root mysql password).

I couldn't agree more... IF

I couldn't agree more... IF you are working against just one Drupal site.

However, there are some components of simplesql that handle some of my requirements, that drush won't.

* I like to be able to read/edit a dump. So I include the --skip-extended-insert. I have modified my drush for this.... but it requires a change to every drush copy on all the servers. And, it was a quickie... I would prefer it as an option. Because, somtimes I just want a backup...

* The dumpdrupal is even more often used, as it allows for a full dump of all the data (20% of DB) without all the cacheing and logs (80%) of the DB. This is a huge space savings and very valuable when cloning a Drupal DB for testing or transfers.

* And then there was the alter command. I don't think drush can cross all DB bounderies and change everything whole hog.... This can... but of couse USE WITH EXTREME CAUTION!!!.

So, yes... learn and use drush. Upgrade often as there are many new features... And perhaps, I will roll some of my per-DB functions back into drush later. But for now, it made sense to release this for other people to enjoy.

medyum

I would also recommand Drush for this kind of Drupal-related database maintenance. If not only for the fact that it reads the settings.php instead of using a custom config file where users can store any password (like the root mysql password).

 

medyum

http://www.medyumca.com

More drush = less code

You should write your script as a drush extension. If only to take advantage of the new site aliases feature.  http://drupal.org/node/670460

Also, I understand the drush dump/sql-sync command handles exclusion list (no data from certain tables) because I asked Moshe about this at Drupalcon SF. I don't know the syntax though.

I must agree with you that it

I must agree with you that it does get irritating using the mouse and at times when it gets stuck up it infuriates you further. All PCs should come with a GUI. With technology, application and software moving ahead you wonder why the devices are still out dated.

© 2009 the Worx Company
site designed by the Worx Company · site hosted by Hosts of America