Using tables with dashes in MySQL queries


You have some databases in MySQL that contain dashes in their names, and when you try to use them (ie grant access to them), you get the following error:


To be able to use them, enclose the database name in backticks (`) like:

Find out the tables storage engine in your MySQL database


You would like to check the storage engine in a MySQL database.


Use the following query after logging in to the server:

Taken from here

Exporting query results from MySQL


You would like to export some query results from MySQL into a format that can be imported in LibreOffice, OpenOffice or Excel.


Try first with the default export options, as by doing a google search, there are a lot of different options for specifying field delimeters, lines terminated, etc.
So by not specifying any additional options the export is a tab delimited, linefeed-terminated file which should work in most of the programs.
So in order to do that you would need a folder in the MySQL server that should have write access. Usually /tmp should do. Then you can build your query and at the end add the INTO OUTFILE ‘/path’, like:

You can use any file ending but usually by specifying .csv the program that you will try to open will understand it.

Enabling MySQL server to be remotely accessible in Amazon EC2


You want to make your instance’s mysql server in Amazon available remotely, and you have set the firewall setting in your security group to allow access to port 3306, but you get the following error:


You would need to edit your /etc/mysql/my.cnf file to allow access to the mysql server by changing the line:


Make sure that the IP used is the private ip and not the Elastic IP.
You should be able to find that in your instance control panel.

Connect to a remote MySQL server with MySQLBrowser using SSH


You would like to connect to a remote MySQL server using the Mysql-query-browser GUI tool, and you only have localhost access to the remote server, but also have ssh access to the remote server.



You can use the following command to start a port forwarding to your localhost and then use that to connect to the remote database server:

You could then use the following to the Mysql-query-broser connection:


converting MySQL sysdate to local timezone

You are hosting your MySQL server in a shared host which is in a different country from your application’s local timezone, and you cannot change the MySQL system timezone, but you would like to use sysdate for date comparisons.

In your SQL query that you use for comparing with the system date/time, use the convert_tz function in MySQL, using the appropriate local time zone (ie Europe/London):

Rails – Mysql::Error: Got error 28 from storage engine

Trying to access your rails application in your development pc, you get the error:

Mysql::Error: Got error 28 from storage engine

in your console.

It turns out that this specific error is a MySQL error, indicating that you have run out of space in the partition that the MySQL server stores its files (/var/lib/mysql).
Looking at the folder there, you can see a very large file called ibdata1.
This file holds all the information about your InnoDB tables and transactions in your MySQL. According to other posts after a Google search, it seems that this file cannot be reduced in size either by removing/truncating your tables or deleting databases that you don’t need. There are quite a few solutions out there if you really need to keep a backup of your databases, but if you only using your database for development and you DON’T NEED (!!) your data or tables, you can move this big ibdata1 to another partition for backup and restart your mysql, that will create a new file.

Rails find case sensitive search

You want to use find in Rails for a case sensitive search. For example in your authentication logic you have something to find the user to login as in:
If you don’t want to limit the available logins with case insensitive validation in the model, then the above code will not work if you have ‘Username’ and ‘username’ as available logins, as the find will only return one of them.

Change the find method to use the BINARY keyword in your database (only used with MySQL), as in the following:
u=User.find(:first, :conditions => [“BINARY login = ?”, login])