Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

http://installingcats.com

Export mysql table into csv

Use /tmp, as mySql doesn't have write privileges everywhere.

select * into outfile '/tmp/outfile.txt' fields terminated by ',' from my_table_name;

change mysql user password

From terminal (square brackets denote your input, do not actually include the brackets):

mysqladmin -u [user] -h localhost -p password '[new_password]'

Test php mysql pdo_mysql

// description of your code here

<?php $link = mysql_connect('localhost','mydbuser','mydbpassword');
if (!$link) {
        die('Could not connect to MySQL: ' . mysql_error());
} echo 'mySql Connection OK';
mysql_close($link);

$dbh = new PDO('mysql:host=localhost;dbname=test','mydbuser','mydbpassword');
if ($dbh) {
        echo 'mysql_pdo CONNECTION OK';
}
else {echo 'mysql_pdo ERROR';}
?>

import data into mysql

Things to note:
Mysql may not have access to the directory you've put the datafile. Use /tmp to overcome this problem.
Datafile name must be the same as the mysql table you're importing to.

mysqlimport -u username -p --columns=column_1,column_2 --fields-terminated-by=',' databasename /tmp/data_file_same_as_mysql_table_name

add mysql symbolic link to OS X MacPorts installed mysql

instead of having to type out mysql5 each time I want to run mysql, make a symbolic link to mysql5

ln -s ../lib/mysql5/bin/mysql /opt/local/bin/mysql

mysql on OS X

mysql installed via ports by default resides in

/opt/local/share/mysql5/mysql


from this location you can start/stop mysql with the following

./mysql.server stop
./mysql.server start


to have a my.cnf file to edit

sudo cp my-small.cnf my.cnf

/tmp/mysql.sock file not found

first finds where your .sock file is

second sets a symbolic link to the sock so Rails' default location for the sock is cool

mysql_config --socket

sudo ln -s  /var/run/mysqld/mysqld.sock /tmp/mysql.sock

mysql add user

// description of your code here

mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

change mysql root password

// description of your code here

mysql -h localhost -u root
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('root-pwd') WHERE user='root';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

Show foreign keys for table in mysql

// description of your code here

show create table <table_name>