Mnesia : ejabberd : Export all tables as SQL queries to a file - mysql

I need to migrate mnesia to mysql from ejabberd.
I have tried many ways from ui : From ui there is a node. On selection of node I will have many options out of which one option is backup. On that page there is a option of Export all tables as SQL queries to a file: host(0.0.0.0),I tried to take sql backup but file is empty
I also tried these commands:
ejabberdctl export2odbc localhost /var/lib/ejabberd/new_file.sql. This is also a blank file generating no error.:
ejabberdctl export2sql localhost /tmp/sql /var/lib/ejabberd/new.sql. This command does not execute as export2sql does not exist.
Is there any other way to take sql dump from Mnesia
Version : ejabberd 16.01 mysql 5.6.xx

The sql export command was added in 16.04 and named as export_sql and later renamed to export2sql in 16.06. So there's no way to take a dump directly, but you have two alternatives:
If you can upgrade ejabberd, then its straight forward, upgrade the server, take a dump of the sql.
Take a backup of the relevant folders, like database/spool directory, config directory, etc.
Upgrade the server to the latest version or at least version 17.07 (the reason being since version 17.06 most of the tables can be exported to sql file, but 17.03-17.06 suffers a bug.
Configure ejabberd to use mysql as a backend database.
Make sure the following modules have the db_type: sql option.
mod_announce, mod_caps, mod_irc, mod_last, mod_muc, mod_offline, mod_privacy, mod_private, mod_pubsub, mod_roster, mod_shared_roster, mod_vcard, mod_vcard_xupdate
Restore the spool directory and make sure you have the same permissions
for all the files and sub-directories as before.
Run the ejabberd2sql with hosts and the sql filename as parameters
Note: If you only need the sql dump you might want to revert back the configuration after the dump.
If you cannot upgrade the server, you can install the latest version of ejabberd in another machine, copy the database directory, follow the same procedure above and you can get the dump of your sql.

Related

Docker MySQL server failed [duplicate]

I am trying to import time zones according to this document: http://dev.mysql.com/doc/refman/5.7/en/mysql-tzinfo-to-sql.html.
When I try hitting even first command through terminal i.e.
mysql_tzinfo_to_sql tz_dir
it says
There were fatal errors during processing of zoneinfo directory 'tz_dir'
When I run:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
then it returns
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
Operating System: Ubuntu
Server: XAMPP (having mariadb)
So, I am not able to import timezone data into the zone tables of mysql database.
I also had this issue this morning while trying to populate the timezone tables on our production server (using CentOS).
I worked around this problem by exporting the table creation script from my development computer (populating the tables on Windows simply requires to download the tables and copy them in the proper directory).
I tweaked the creation script a little bit and it is now working for me:
I cannot post it in my answers since the script is too long.
https://drive.google.com/file/d/0B7iwL5F-hwr_YkItRXk2Z1VZdlE/view?usp=sharing
Here's a version with the comment (but it doesn't seems to work, so use the version without comments).
https://drive.google.com/file/d/0B7iwL5F-hwr_dWdjTDREcXNHQmM/view?usp=sharing
The script should take no more than a few second to run. You'll probably need to use the root user to be able to run it.
You can use this query in order to validate the installation:
SELECT CONVERT_TZ(CURRENT_DATE(),'UTC','America/Montreal');
If it returns NULL instead of a datetime, it means the script failed.
Good success
The
There were fatal errors during processing of zoneinfo directory 'tz_dir'
error message means that the directory cannot be read (not enough access rights or not even exists).
Knowing that the mysql_tzinfo_to_sql program is just a tool that converts a bunch of timezone files into an SQL script that you can use to install the time zones for mysql, your task is the following:
obtain the timezone files from somewhere
execute mysql_tzinfo_to_sql to create an SQL script from those files
execute that SQL script in your mysql database.
These steps can be performed on different computers if you transfer the files between them. For example, I installed the timezones on a machine where the mysql installation was not complete, that is, mysql_tzinfo_to_sql was not available and I wasn't able to install it either.
In such a case you can combine the following steps:
if mysql_tzinfo_to_sql is not available on the computer where your mysql database resides then find a computer where mysql_tzinfo_to_sql is already installed
make the zoneinfo folder available on that computer. It is just a bunch of files in different folders so you can transport them in a gzip file from one computer to the other. In a normal mysql installation this folder should exist but maybe your installation is not complete, su just get it from anywhere.
execute the mysql_tzinfo_to_sql command to create an SQL script like this:
mysql_tzinfo_to_sql path-to-your-zoneinfo-folder >install_mysql_zoneinfo.sql
move the created SQL script to the computer where your mysql database resides *
execute the script like this:
mysql --user=root --password=abc123 mysql <install_mysql_zoneinfo.sql
Adjust the username and password if needed and your script will be executed. This will fill up the timezone-related tables with the appropriate values and you will be able to use them:
SELECT convert_tz(NOW(),'UTC','Australia/Melbourne');
if you can reach the mysql database from the computer where the SQL script was generated then it's enough to add the -h <hostname> command line argument to the subsequent script-executing program and you will not have to copy the SQL script to the target machine.

What is the windows path to the MySQL connections file?

I come from the oracle world where the tnsnames.ora file contain all the sql connection information.
I cannot seem to find the file containing such information for mysql. Could someone with a windows machine tell me where I can find it please.
MySQL doesn't need a connections file analogous to the .tns file. MySQL has nothing like a TNS. Connection parameters typically are configured explicitly in your application.
You can optionally create a file called .my.cnf that contains a user's default parameters for connecting.
See also What is the location of mysql client “.my.cnf” in Windows? that shows how to use mysql --help to find out the location of all the config files.
Most people just configure one set of connection parameters in their .my.cnf file, but you can configure multiple sets of connection parameters under different [client] groups, and invoke MySQL client tools to use the respective connection. There's an excellent blog that describes how to set this up here: http://datacharmer.blogspot.com/2011/03/hidden-options-file-trick.html
Re your updated info:
Sorry, I had to boot up a Windows box and install MySQL Workbench to check where the connection info is stored. I don't normally use Windows.
Right, for MySQL Workbench, the connection data is in for example,
C:\Users\Uncle Iroh\AppData\Roaming\MySQL\Workbench\connections.xml
But you're not expected to edit this by hand, and you'll probably ruin it if you try. It's undocumented, and presumably the format could change if you change versions of MySQL Workbench. You should create or edit connections in the Workbench GUI.
There is no such thing in MySQL. Check for a config file called my.ini or my.cnf. If MySQL is using a non-default port (not 3306), it will be detailed there. Otherwise, connect using:
mysql -u user -p
This is an executable (mysql.exe) you'll find in the bin directory of the installation (probably). For example, on my Windows box it's here: C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin\mysql.exe

inspect mySQL database

I have a mySQL database on my Windows PC. I'm pretty sure I've found the relevant files, namely the following:
formula.frm
formula.ibd
db.opt
What is the natural way to inspect, edit, and generally play with the contents of these files?
You do not view the binary database files directly. MySQL is a service that you connect to with a client and then perform SQL commands. You will need a client (such as MySQL Workbench) to work with the server.
MySQL Workbench is the GUI tool that allows you to connect to a MySQL database and perform actions on it including querying and creating/modifying the various parts of the database.
MySQL Workbench intro: http://dev.mysql.com/doc/workbench/en/wb-intro.html
Getting started with MySQL: http://dev.mysql.com/doc/refman/5.6/en/tutorial.html
There is also the command-line utility that is included when you install the server. It will be in the BIN folder of the MySQL install directory.
Command-line client info: http://dev.mysql.com/doc/refman/5.1/en/mysql.html
Use a tool like Mysql Workbench to connect to the DB. You do nothing directly to the files. You connect to the service and use the DB.
William, it sounds like your question is "how do I take mysql binary files and turn them into something usable on my machine?". If that's the case, you'll want to first install MySQL on your machine if you haven't already. Then you might have a look here for how to recreate a database from a .ibd file.

Created a mysql database but can't seem to find it anywhere

I just cloned a repo from github and bundle installed everything and created a mysql db via rake db:create. I migrated the database and everything....however, I have no idea where it is located? Usually when I use sqlite, it's in the db/ folder...but this database is not. where can I find it?
Look in your MySQL config file. Usually it's called my.cnf. Where to find this config on your system, we can't say :-)
Look for datadir in a config file
[mysqld]
datadir=/var/lib/mysql/
MySQL works a bit differently than sqlite. Whereas sqlite writes a database directly to a file (in your db/ directory in the case of rails), MySQL writes it to a server (usually located on the same machine as your application, but not always). I would be surprised if an app you cloned off of github let you create a mysql database right off the bat. You need to set up a mysql server and set a password for it. If you're running Ubuntu -- as I am -- these are some good instructions. Then you need to configure your config/database.yml file accordingly.

MySQL command line client for Windows

Is there any nice command line MySQL client for windows? I mean a single exe that allows connecting and running a sample query. I've googled and only could find big graphical environments like toad or mysql workbench. I need only a simple command line tool, where can I download sth like this?
EDIT: I don't want to install the whole MySQL package on my PC. I know it's inside the mysql package but how do I download only this cmd line client. Because i don't need anything else.
When you go to the MySQL download page, choose the platform "Microsoft Windows". Then download the "Windows (x86, xx-bit), ZIP Archive" (be sure to select the one with size over 140M.
The binaries will be in the "bin" folder.
I understand that this is not just the client binaries, but at least you don't have to install and setup the entire server.
mysql.exe can do just that....
To connect,
mysql -u root -p (press enter)
It should prompt you to enter root password (u = username, p = password)
Then you can use SQL database commands to do pretty much anything....
You can choose only install the client during server install. The website only offers to let you download the full installer (grab whatever version you want from http://www.mysql.com/downloads/mysql/).
In the install wizard, when prompted for installation type (typical, minimal, custom), choose 'Custom'. On the next screen, select to NOT install the server, and proceed with the rest of the install as normal.
When you're done, you should see just the relevant client programs (mysql, mysqldump, etc) in C:\Program Files\MySQL..\bin
Its pretty simple. I saved the mysql community server in my D:\ drive. Hence this is how i did it.
Goto D:\mysql-5.7.18-winx64\bin and in the address bar type cmd and press enter, so command prompt will open. Now if you're using it for the first time type as mysql -u root -ppress enter. Then it will ask for password, again press enter. Thats it you are connected to the mysql server.
Before this make sure wamp or xampp any of the local server is running because i couldn't able to connect to mysql wihthout xampp running.
Happy Coding.
You can also download MySql workbench (31Mo) which includes mysql.exe and mysqldump.exe.
I successfully tested this when i had to run Perl scripts using DBD:MySql module to run SQL statements against a distant MySql db.
You can access mySQL in command line just by typing:
C:\www\mysql\bin> mysql -u root -p
After which you can type sql commands normally such as:
mysql> SHOW DATABASES;
Here, I am assuming you mySQL installation directory is C:\www\mysql.
I have similar requirement where I need a MySQL client but not server (running in a virtual machine and don't want any additional overhead) and for me the easiest thing was to install MySQL community server taking typical installation options but NOT configure the server, so it never starts, never runs. Added C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin to system path environment variable and I'm able to use the MySQL command line client mssql.exe and mysqladmin.exe programs.
If you are looking for tools like the the mysql and mysqldump command line client for Windows for versions around mysql Ver 14.14 Distrib 5.6.13, for Win32 (x86) it seems to be in HOMEDRIVE:\Program Files (x86)\MySQL\MySQL Workbench version
This directory is also not placed in the path by default so you will need to add it to your PATH environment variable before you can easily run it from the command prompt.
Also, there is a mysql utilities console but it does not work for my needs. Below is a list of the capabilities on the mysql utilities console in case it works for you:
Utility Description
---------------- ---------------------------------------------------------
mysqlauditadmin audit log maintenance utility
mysqlauditgrep audit log search utility
mysqldbcompare compare databases for consistency
mysqldbcopy copy databases from one server to another
mysqldbexport export metadata and data from databases
mysqldbimport import metadata and data from files
mysqldiff compare object definitions among objects where the
difference is how db1.obj1 differs from db2.obj2
mysqldiskusage show disk usage for databases
mysqlfailover automatic replication health monitoring and failover
mysqlfrm show CREATE TABLE from .frm files
mysqlindexcheck check for duplicate or redundant indexes
mysqlmetagrep search metadata
mysqlprocgrep search process information
mysqlreplicate establish replication with a master
mysqlrpladmin administration utility for MySQL replication
mysqlrplcheck check replication
mysqlrplshow show slaves attached to a master
mysqlserverclone start another instance of a running server
mysqlserverinfo show server information
mysqluserclone clone a MySQL user account to one or more new users
mysql.exe is included in mysql package. You don't have to install anything additionally.
download the mysql-5.0.23-win32.zip (this is the smallest possible one) from archived versions in mysql.com website
cut and paste the installation in c drive as mysql folder
then install then follow instructions as per this page:
https://cyleft.wordpress.com/2008/07/20/fixing-mysql-service-could-not-start-1067-errors/
For Windows users:
1.Install the full version of MYSQL
2.On the Windows 10 start button click on search and type in MySQL
3. Select the MYSQL Command Line Client 5.5 (I am using version 5.5)
4. go ahead and run your sql queries/
5. to exit type \q or quit