Never been to TextSnippets 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

« Newer Snippets
Older Snippets »
10 total  XML / RSS feed 

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>

mysql backup / restore

// description of your code here
exports given database to a textfile which can then be zipped and downloaded or sent somewhere (mailing pending)
mysqldump -u <username> -p -q --single-transaction <db_name> > <backup_filename>


To restore the database (be sure to create the target DB before running this)
mysql -u <username> -p <db_name> < <backup_filename>


To backup and restore data only, use -t, no table data
mysqldump -u <username> -p -q --single-transaction -t <db_name> > <backup_filename>


Then restore from command line as usual.
mysql -u <username> -p <db_name> < <backup_filename>

ssh tunnel for mysql

// description of your code here

No forking in background and verbose

ssh -2 -v -c blowfish -C -N user@servername.textdrive.com -L 3370/127.0.0.1/3306



Forking in background

ssh -2 -f -c blowfish -C -N user@servername.textdrive.com -L 3370/127.0.0.1/3306

« Newer Snippets
Older Snippets »
10 total  XML / RSS feed