Categories: Uncategorized

My disaster with MYSQL and MariaDB on Mac

My disaster with MYSQL and MariaDB on Mac OSX

Here are my notes on what I could and could not get working. These are reasons why I got with SQLite for now

 

Join my FREE newsletter to learn why I went with SQLite for automated trading

Diagnostic fixes for MYSQL on Mac OS X
Potentially reset Root password for MYSQL
http://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/

If you get error of:
After MySQL install via Brew, I get the error – The server quit without updating PID file

http://stackoverflow.com/questions/9624774/after-mysql-install-via-brew-i-get-the-error-the-server-quit-without-updating
Run

sudo chown -R _mysql:_mysql /usr/local/var/mysql

Try restarting the MYSQL daemon with
sudo /usr/local/mysql/support-files/mysql.server start

——-
Note: I tried Maria where the InnoDB Engine generated an error
To install MariaDB, use

https://mariadb.com/kb/en/mariadb/building-mariadb-on-mac-os-x-using-homebrew/

Another way to remove MYSQL to be replaced by MariaDB, follow:

OSX How To: Uninstall native MySQL and install MariaDB via Homebrew

This is a short overview on how to completely remove any old mysql server installs in OSX and upgrade to MariaDB without conflicts. Things can get a bit weird when you have various old installs of MySQL server floating around, and utilizing homebrew to install and upgrade MariaDB as a drop in replacement for MySQL has worked well, especially if you’re used to managing MySQL installs via yum in linux.

First: Backup Your Data!

Backup all of your current databases with mysqldump

This isn’t a tutorial on backups, and there are many ways to do it. You should know how to backup your data anyway. For this example, we’ll do a full backup of our InnoDB databases.

$ mysqldump -uroot -p --all-databases --flush-logs --master-data=2 > all_databases.sql

Second: Backup Your MySQL User Permissions

Within the msyqldump above, make sure you have dumped the mysql.users table. Either do this, or dump your mysql table data independently, or make note of your existing mysql user permissions if you just want to manually add them to your clean new MariaDB server later. If you have a lot of different permissions setup, you will probably want to migrate them. If you don’t have many db users, you may want to add them manually later so you can get a refresher of how your user permissions are setup. Either way, you should understand your user permissions before removing your old database.

Dump your existing mysql table:

$ mysqldump -uroot -p mysql > mysql.sql

After installing your new MariaDB server, you can restore the mysql database by executing:

$ mysql -uroot -p mysql < mysql.sql

then make sure to flush privileges for the new user permissions to take effect:

FLUSH PRIVILEGES

Remove MySQL

You are now ready to remove everywhere MySQL has put itself into your OSX system. You may opt to move these folders to a backup folder instead of removing them, but for our case, we want to remove MySQL completely so there are no conflicts later.

First, check where mysql is running on your system:

$ which mysql

You should see something like: /usr/local/mysql

Now, stop the database server:

$ sudo /usr/local/mysql/support-files/mysql.server stop

And move/backup or remove the following folders/files:

  • sudo rm /usr/local/mysql
  • sudo rm -rf /usr/local/mysql*
  • sudo rm -rf /Library/StartupItems/MySQLCOM
  • sudo rm -rf /Library/PreferencePanes/My*
  • rm -rf ~/Library/PreferencePanes/My*
  • edit /etc/hostconfig and remove the line MYSQLCOM=-YES-

These may not exist, but if they do, remove them to avoid any conflicts with other versions of MySQL:

  • sudo rm -rf /Library/Receipts/mysql*
  • sudo rm -rf /Library/Receipts/MySQL*
  • sudo rm -rf /private/var/db/receipts/*mysql*

Install MariaDB with Homebrew

First, make sure you have homebrew installed and running, and make sure everything is up to date:

$ brew update

You can then run searches (brew search mariadb) , and if you would like to get more information about it, you could do: brew info mariadb. When you’re ready to install MariaDB, simply execute:

$ brew install mariadb

After homebrew installs MariaDB server, follow the onscreen instructions on how to install the database (mysql_install_db) and add your startup scripts if you want MariaDB to load on boot. You should also run mysql_secure_installation to lock down your install and set your root password.

You should now be able to login to mysql with your new root user and see the MariaDB message from the server:

$ mysql -uroot -p


Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 48
Server version: 10.0.14-MariaDB Homebrew

You can now import your mysql users and dumped databases file as needed.

This should remove any conflicts with MYSQL if you intend to replace with MariaDB
As noted run: mysql_install_db

*** Follow any instructions of the output from this script
eg.
usr/local/Cellar/mariadb/10.1.9/bin/mysqld –skip-grant –general-log &

——-

For the C Connector which is compatible with MYSQL

Follow these instructions
http://blog.davenicholas.me.uk/2013/04/how-to-c-mysql-mac-osx.html
For Xcode configurations:
http://stackoverflow.com/questions/31440170/mac-xcode-6-4-header-include-path
These changes are under ‘Builder Settings”

In the same menu you now need to add the linker flags in the Linking section.

Other Linker Flags: -lmysqlclient -lm -lz

Add to both Debug and Release but also note configuration needed in addition with:
In the same menu you now need to add the linker flags in the Linking section.

I have confirmed that this can be built with the following modified C++ code:

//blog.davenicholas.me.uk/2013/04/how-to-c-mysql-mac-osx.html

#include <mysql.h>

#include <iostream>

#include <vector>

int main(int argc, const char * argv[]) {

std::vector<std::string> tables;

MYSQL_RES *result;

MYSQL_ROW row;

MYSQL *connection, mysql;

int state;

mysql_init(&mysql);

connection = mysql_real_connect(&mysql,”localhost”,”username”,”password”,”database”,0,0,0);

if (connection == NULL)

{

std::cout << mysql_error(&mysql) << std::endl;

return 0;

}

state = mysql_query(connection, “SHOW TABLES”);

if (state !=0)

{

std::cout << mysql_error(connection) << std::endl;

return 0;

}

result = mysql_store_result(connection);

std::cout << “tables: ” << mysql_num_rows(result) << std::endl;

while ( ( row=mysql_fetch_row(result)) != NULL )

{

tables.push_back(row[0]);

}

mysql_free_result(result);

mysql_close(connection);

return 0;

}

—-

How to install libaries for Postgres but did not get this working on any Mac OSX IDE

sudo find / -name libpq
/Applications/Postgres.app/Contents/Versions/9.4/include/libpq
/Applications/Postgres.app/Contents/Versions/9.4/include/postgresql/internal/libpq
/Applications/Postgres.app/Contents/Versions/9.4/include/postgresql/server/libpq
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/Users/quantlabsnet/.Trash/libpqxx-4.0.1/config/sample-headers/libpq
/Users/quantlabsnet/Documents/cpp/pg/libpqxx-4.0/config/sample-headers/libpq
This works with brew:
brew install homebrew/versions/libpqxx3

It also attempts to builds the library locally but in my casE:

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink include/pqxx/basic_connection
Target /usr/local/include/pqxx/basic_connection
already exists. You may want to remove it:
rm ‘/usr/local/include/pqxx/basic_connection’

Sometimes think may not work with a link to work so I did:

brew install libpqxx

Results:
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink include/pqxx/basic_connection.hxx
Target /usr/local/include/pqxx/basic_connection.hxx
already exists. You may want to remove it:
rm ‘/usr/local/include/pqxx/basic_connection.hxx’

To force the link and overwrite all conflicting files:
brew link –overwrite libpqxx

To list all files that would be deleted:
brew link –overwrite –dry-run libpqxx

So I ran: brew link –overwrite libpqxx

97 symlinks were created
headers can be located in /usr/local/include/pqxx/version.hxx

libpqxx located in (sudo find / -name libpqxx)
/usr/local/Cellar/libpqxx
/usr/local/Library/LinkedKegs/libpqxx
/usr/local/opt/libpqxx

Or

/usr/local/lib/libpqxx.a

Source code examples from http://www.tutorialspoint.com/postgresql/postgresql_c_cpp.htm

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!
caustic

Hi i there My name is Bryan Downing. I am part of a company called QuantLabs.Net This is specifically a company with a high profile blog about technology, trading, financial, investment, quant, etc. It posts things on how to do job interviews with large companies like Morgan Stanley, Bloomberg, Citibank, and IBM. It also posts different unique tips and tricks on Java, C++, or C programming. It posts about different techniques in learning about Matlab and building models or strategies. There is a lot here if you are into venturing into the financial world like quant or technical analysis. It also discusses the future generation of trading and programming Specialties: C++, Java, C#, Matlab, quant, models, strategies, technical analysis, linux, windows P.S. I have been known to be the worst typist. Do not be offended by it as I like to bang stuff out and put priorty of what I do over typing. Maybe one day I can get a full time copy editor to help out. Do note I prefer videos as they are much easier to produce so check out my many video at youtube.com/quantlabs

Recent Posts

My Journey with Algorithmic Trading in Rust

This article chronicles my experience, exploring the motivations behind this choice and the unique advantages …

16 hours ago

Dive into kdb+ and q: A Guide to Learning Resources

But where do you begin your kdb+ and q journey? Don't worry, aspiring q programmers!…

4 days ago

High-Frequency Trading Meets High-Performance Computing: Building Your Dream Career

The world of high-frequency trading (HFT) thrives on speed and precision, and high-performance computing (HPC)…

5 days ago

Python Powers Algorithmic Trading: Mastering the Market with Code

This article explores the exciting opportunities for Python which powers algorithmic trading, equipping you with…

5 days ago

Allure and Limitations of Open-Source Algorithmic Trading Systems

Here, we delve into the potential limitations of relying solely on open-source projects for youropen-source…

5 days ago

Demystifying Latency: A C++ Deep Dive into High-Frequency Trading

Today, we join Brian, host of quantlabs.net, as he explores the intricate relationship between C++deep…

5 days ago