top of page

Get auto trading tips and tricks from our experts. Join our newsletter now

Thanks for submitting!

Writer's pictureBryan Downing

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

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:

  1. sudo rm /usr/local/mysql

  2. sudo rm -rf /usr/local/mysql*

  3. sudo rm -rf /Library/StartupItems/MySQLCOM

  4. sudo rm -rf /Library/PreferencePanes/My*

  5. rm -rf ~/Library/PreferencePanes/My*

  6. 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:

  1. sudo rm -rf /Library/Receipts/mysql*

  2. sudo rm -rf /Library/Receipts/MySQL*

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

0 views0 comments

Comments


bottom of page