Archive

Archive for the ‘mysql’ Category

homebrew + mysql = installed but access denied for root

November 14th, 2011 rupert Comments off

1. Cleanup
I have an existing mysql @ /usr/local/mysql, so we remove that.

% sudo rm -rf mysql-5.1.43-osx10.6-x86_64

Note: I suggest you backup your mysql data by doing mysqldump prior to removing the old mysql.

2. Install mysql

#brew install mysql
Set up databases to run AS YOUR USER ACCOUNT with:
    unset TMPDIR
    mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
 
To set up base tables in another folder, or use a different user to run
mysqld, view the help for mysqld_install_db:
    mysql_install_db --help
 
and view the MySQL documentation:
  * http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html
  * http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html
 
To run as, for instance, user "mysql", you may need to `sudo`:
    sudo mysql_install_db ...options...
 
Start mysqld manually with:
    mysql.server start
 
    Note: if this fails, you probably forgot to run the first two steps up above
 
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
 
To connect:
    mysql -uroot
 
To launch on startup:
* if this is your first install:
    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/Cellar/mysql/5.5.15/com.mysql.mysqld.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
 
* if this is an upgrade and you already have the com.mysql.mysqld.plist loaded:
    launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
    cp /usr/local/Cellar/mysql/5.5.15/com.mysql.mysqld.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
 
You may also need to edit the plist to use the correct "UserName".
 
Warning: m4 macros were installed to "share/aclocal".
Homebrew does not append "/usr/local/share/aclocal"
to "/usr/share/aclocal/dirlist". If an autoconf script you use
requires these m4 macros, you'll need to add this path manually.
==> Summary
/usr/local/Cellar/mysql/5.5.15: 6277 files, 217M, built in 4.9 minutes
brew install mysql  498.39s user 83.40s system 135% cpu 7:08.37 total
~/Desktop% unset TMPDIR
~/Desktop% echo $TMPDIR
 
~/Desktop% mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
Installing MySQL system tables...
OK
Filling help tables...
OK
 
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
 
/usr/local/Cellar/mysql/5.5.15/bin/mysqladmin -u root password 'new-password'
/usr/local/Cellar/mysql/5.5.15/bin/mysqladmin -u root -h rupert-imac password 'new-password'
 
Alternatively you can run:
/usr/local/Cellar/mysql/5.5.15/bin/mysql_secure_installation
 
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
 
See the manual for more instructions.
 
You can start the MySQL daemon with:
cd /usr/local/Cellar/mysql/5.5.15 ; /usr/local/Cellar/mysql/5.5.15/bin/mysqld_safe &
 
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/Cellar/mysql/5.5.15/mysql-test ; perl mysql-test-run.pl
 
Please report any problems with the /usr/local/Cellar/mysql/5.5.15/scripts/mysqlbug script!
~/Desktop% which mysql.server
/usr/local/bin/mysql.server
~/Desktop% ls -la `which mysql.server`
lrwxr-xr-x  1 rupert  admin  39 30 Dec 11:20 /usr/local/bin/mysql.server@ -> ../Cellar/mysql/5.5.15/bin/mysql.server
~/Desktop% mysql.server start
Starting MySQL
.. SUCCESS!

3. That’s it? No.

At the time of writing this, mysql is at 5.5 and was installed successfully by homebrew. However, I cannot login using the root account. Have a read of this stackoverflow: brew install mysql on mac os.

To fix this, stop mysql

launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist

and start mysql by skipping the grant tables.

mysqld_safe --skip-grant-tables

Depending if you have a record in mysql.user (select * from mysql.user), then you can either create or update the user.

create:

GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' IDENTIFIED BY 'whatever' WITH GRANT OPTION;
FLUSH PRIVILEGES;

update:

UPDATE mysql.user SET Password = PASSWORD('NewPassword') WHERE User='root';
FLUSH PRIVILEGES;

4. Cleanup paths
This is just removing the pgsql and mysql from the current path

export PATH=$PATH:$ORACLE_HOME:$MYSQL_HOME/bin:$CLANG_HOME:$ANDROID_HOME/tools:$APACHE2_HOME/bin:$MAGICK_HOME/bin:$SPHINX_HOME/bin:$PGSQL_HOME/bin
Categories: homebrew, mysql, osx Tags: , ,

how to use a schema name in mysql2psql

August 8th, 2011 rupert Comments off

Below is a summary of my experiences with migrating from MySQL to Postgres using mysql2psql – https://github.com/maxlapshin/mysql2postgres

%gem install mysql2psql

To migrate a “tsa” database from mysql to postgres, create a tsa.yml

mysql:
 hostname: localhost
 port: 3306 
 socket: /tmp/mysql.sock
 username: dbadmin 
 password: password
 database: tsa
 
destination:
 # if file is given, output goes to file, else postgres
 #file: tsa.dump
 postgres:
  hostname: localhost
  port: 5432 
  database: tsa:hotels #database_name:schema_name
  username: dbadmin
  password: password
 
# if tables is given, only the listed tables will be converted.  leave empty to convert all tables.
#tables:
#- table1
#- table2
# if exclude_tables is given, exclude the listed tables from the conversion.
#exclude_tables:
#- table3
#- table4
 
# if supress_data is true, only the schema definition will be exported/migrated, and not the data
supress_data: false
 
# if supress_ddl is true, only the data will be exported/imported, and not the schema
supress_ddl: false
 
# if force_truncate is true, forces a table truncate before table loading
force_truncate: false

Run.

%mysql2psql tsa.yml

References:
http://en.wikibooks.org/wiki/Converting_MySQL_to_PostgreSQL

Categories: mysql, postgres Tags: ,

Mac Shortcuts

August 31st, 2008 rupert Comments off
Categories: mac, mysql Tags:

Switching Back and Forth in MySQL and PostGres

November 2nd, 2007 rupert Comments off

There is no way I could accomplish better data manipulation between MySQL and PostGres without Navicat. Just to be clear, I do not work for Navicat. These tools were able to help me export data out of MySQL and import it to PostGres. It is just one of those products that really deserve credit.

Navicat

Take note though that you can not see the “messages” displayed by the “raise command” in PL/PGSQL when using Navicat 8 for PostGres. I have to switch back to using pgAdmin III or my standard command line.

Categories: mysql, postgres Tags:

Debian MySQL

October 30th, 2007 rupert Comments off

A default install of mysql on debian would have bind-address set to 127.0.0.1. This is why you can’t accept remote connections to your mysql. In order to establish remote connections to mysql on debian servers, please comment the bind-address as shown below.

 42 language    = /usr/share/mysql/english
 43 skip-external-locking
 44 #
 45 # Instead of skip-networking the default is now to listen only on
 46 # localhost which is more compatible and is not less secure.
 47 #bind-address = 127.0.0.1
 48 #
Categories: debian, mysql Tags: ,