Using a primary key not named id with Ecto and Mysql

Problem

You would like to use a legacy or a database you don’t have control over, with Phoenix, but the primary key of the table it is not named ‘id’.

Solution

You can define the primary key using the @primary_key as in:

Taken from here

ERROR 1290 (HY000): The MySQL server is running with the –secure-file-priv option so it cannot execute this statement

Problem

You want to export a MySQL database table as a csv with something like:

but you get the error that MySQL cannot execute this command.

Solution

Find out the location that MySQL can use to export files by running the following:

and then use the path to change the outfile path (ie /var/lib/mysql-files/table_name.csv).

Taken from the answer here

Create a MySQL table with dashes

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

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

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

rails `require’: cannot load such file — mysql2/mysql2 (LoadError)

Problem

You want to use a different ruby version from the one you have initially installed and build your application with, but when you change it in your rvm installation you get the following error:

Solution

To make it work again you will have to uninstall the mysql2 gem and install it again in the new ruby version with the option –platform=ruby.

Exporting query results from MySQL

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

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.