Create a MySQL table with dashes

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You want to create a MySQL table that contains spaces, but when you try you get the following error message:

Solution

Use the backticks to create the table:

Using tables with dashes in MySQL queries

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

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:

Solution

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

Find out the tables storage engine in your MySQL database

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

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

Solution

Use the following query after logging in to the server:

Taken from here

Exporting query results from MySQL

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

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

Solution

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

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

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:

Solution

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

to

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

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

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.

 

Solution

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

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem
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.

Solution
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):
convert_tz(sysdate(),'SYSTEM','Europe/London')

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

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem
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.

Solution
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.