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!)

« Newer Snippets
Older Snippets »
Showing 21-40 of 61 total

/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

Launchd item for starting MySQL

This will start MySQL with a low priority on reboot

<?xml version="1.0" encoding="UTF-8"?>
DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Labelkey>
        com.mysql.MySQL</string>
        <key>LowPriorityIOkey>
        />
        <key>ProgramArgumentskey>
        
                /usr/local/mysql/bin/mysqld_safestring>
        </array>
        <key>RunAtLoadkey>
        />
dict>
</plist>

ssh tunnel with local port forwarding (MySQL)

// ssh tunnel remote mysql to a local port (in this case, 3307)

ssh -2 -f -C -N user@servername.com -L 3307/127.0.0.1/3306

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

Export WordPress tables

// description
Export only WordPress tables from mysql database.

mysqldump -u dbname -p username --skip-opt -B --tables wp_categories wp_comments wp_link2cat wp_links wp_options wp_post2cat wp_postmeta wp_posts wp_usermeta wp_users > wordpress.sql


SSH tunnel for mySQL

Connect to remote mysql server via ssh tunnel:

ssh -f -L 3306:127.0.0.1:3306 username@servername.com sleep 120


Should auto-disconnect when it’s no longer in use.

mySQL

Add database user:
grant select, update, create, insert, delete on database.* to username@localhost identified bypassword‘;


Database export:
mysqldump -u root -p database > filename.sql


Database import:
mysql -u root -p database < filename.sql

MySQL dump schema only

// description of your code here

 mysqldump familyman_development -u familyman -p -d  --skip-opt    

LightTPD, PHP, MySQL on FreeBSD

// A method for installing LightTPD, PHP, MySQL on FreeBSD
// All source is stored in /usr/local/src
// Source tarballs are in /usr/local/src/tarballs
// Note this works pretty much the same on Mac OS X
// and I've done it on Ubuntu 6.06
# Have to do this via my Mac because of all the mirror servers
# I use scp to copy from Mac to FreeBSD box
# Downloaded into /usr/local/src/taballs:
- php-5.2.0.tar.bz2 from http://www.php.net/downloads.php
- mysql-5.0.27.tar.gz from http://dev.mysql.com/downloads/mysql/5.0.html#downloads

# On FreeBSD box
cd /usr/local/src
cd tarballs
fetch http://mirrors.cat.pdx.edu/lighttpd/lighttpd-1.4.13.tar.gz
cd ..
tar xzvf tarballs/php-5.2.0.tar.bz2
tar zxvf tarballs/mysql-5.0.27.tar.gz
tar zxvf tarballs/lighttpd-1.4.13.tar.gz

MySQL first
=======================================================
# Shut down MySQL:
/usr/local/mysql/bin/mysqladmin -u root -p shutdown
cd mysql-5.0.27
./configure --prefix=/usr/local/mysql \
            --localstatedir=/usr/local/mysql/data \
            --enable-assembler \
            --with-mysqld-ldflags=-all-static CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 \
            -felide-constructors -fno-exceptions -fno-rtti"

# Change to root
su

# I like to run the process in the background (&),
# redirect the output to a log file,
# and tail -f the log file.

# Make it:
make > ~/mysql_make.log &
# Watch the make:
tail -f ~/mysql_make.log

# Install it:
make install > ~/mysql_install.log &
# Watch the install:
tail -f ~/mysql_install.log

PHP as a CGI:
=====================================================================
cd /usr/local/src/php-5.2.0

# Make sure curl is where we think it is
locate curl | grep include

# Configure it
./configure --with-xml --with-zlib --with-mysql=/usr/local/mysql \
            --with-mysqli=/usr/local/mysql/bin/mysql_config \
            --with-curl=/usr/local/include \
            --enable-cgi --enable-fastcgi \
            --enable-force-redirect \
            > ~/phpconfig.log &
tail -f ~/phpconfig.log

# Edit the Makefile to eliminate duplicates in the EXTRA_LIBS line
pico Makefile
# New: EXTRA_LIBS = -lcrypt -lmysqlclient -liconv -lcurl -lz -lm -lxml2 -lssl -lcrypto

# Make it
make > ~/php_make.log &
tail -f ~/php_make.log

# Install it
make install > ~/php_install.log &
tail -f ~/php_install.log

LightTPD:
=================================================================
# Check requirements
locate libpcre
locate libz

# If those aren't there, find them in ports and install

cd /usr/local/src/lighttpd-1.4.11
./configure --prefix=/usr/local --with-pcre=/usr/local

# Make it
make > ~/lighttpd_make.log &
tail -f ~/lighttpd_make.log

# Install it
make install > ~/lighttpd_install.log &
tail -f ~/lighttpd_install.log

# Start MySQL
/usr/local/etc/rc.d/mysql.server.sh start
@HOSTNAME@: not found
@HOSTNAME@: not found
Starting MySQL. SUCCESS!

# Check MySQL version
/usr/local/mysql/bin/mysqladmin -v
/usr/local/mysql/bin/mysqladmin  Ver 8.41 Distrib 5.0.27, for unknown-freebsd6.0 on i386

# Add mysql to the path for root.
cd
pico .cshrc
 set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /usr/X11R6/bin $HOME/bin)
     becomes
 set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /usr/X11R6/bin $HOME/bin /usr/local/mysql/bin)

# Use the lighttpd.conf file I have posted separately
# Requires use of /var/log/lighttpd log directory
mkdir /var/log/lighttpd
chmod 777 /var/log/lighttpd

# Test the server?
lighttpd -f /usr/local/etc/lighttpd.conf
ps ax | grep light
59463  ??  S      0:00.02 lighttpd -f /usr/local/etc/lighttpd.conf
59537  p0  R+     0:00.00 grep light

# To shut off the server
# pid file is in /var/run/lighttpd.pid

mimimee 123

// description of your code here

index.php
<html>
        <head>
                <script type="text/javascript" src="modul - clock.php">script>
                



"".date("d-m-Y")."<br>".date("H:i:s").""; /*NECESAR pentru a inlocui delay-ul pana ce se incarca script-ul*/?>
"clock" style="position:relative;">



Upload Image To Database

// Code To Upload an image to a database and then update its contents.

# Create an ew classified and attach an image with it.
def create
  image_types = ["image/jpeg", "image/pjpeg", "image/gif","image/png", "image/x-png"]
  @categories = Category.find(:all)
  @classified = Classified.new(params[:classified])
  @classified.user = session[:user]
  unless params[:classified][:picture].blank?
    if (image_types.include?params[:classified][:picture].content_type.chomp)
      @classified.picture = params[:classified][:picture].read
    else
      @classified.errors.add(:picture,  "Photo doesn't seem to be JPG, GIF, or PNG. please ensure it is a valid image file.")
      render :action => 'new'
      return
    end
  end

  if @classified.save
    redirect_to :action => 'list'
  else 
    render :action => 'new'
  end
end


# Update Method So user can change the image associated with their classified
def update
  image_types = ["image/jpeg", "image/pjpeg", "image/gif", "image/png", "image/x-png"]
  @classified = Classified.find(params[:id])
  @categories = Category.find(:all)
  
  if @classified.update_attributes(params[:classified])
    unless params[:classified][:picture].blank?
      if (image_types.include?params[:classified][:picture].content_type.chomp)
        @classified.picture = params[:classified][:picture].read
      else
        @classified.errors.add(:picture, " doesn't seem to be JPG, GIF, or PNG. please ensure it is a valid image file.")
        render :action => 'edit'
        return
      end
    end
    
    flash[:notice] = 'Classified was successfully updated.'
    redirect_to :action => 'show', :id => @classified
  else
    render :action => 'edit'
  end
end

Return the MySQL-formatted date for 60 days from today (PHP)

// Get the date in MySQL date format for 60 days from today

$new_expiration_date = date('Y-m-d',mktime(0,0,0,date('m'),date('d')+60,date('Y')));

Backup a single MySQL table

// Use this to take a single table backup, with elements in double quotes delimited with a comma:

while ($row = mysql_fetch_array($query,MYSQL_NUM)) $output .= "\"" . implode("\",\"",str_replace("\r\n"," ",$row)) . "\"\r\n"; echo $output; // or write $output to a file

How to load a sql dump into a new database

// description of your code here

open up iterm

change to the directory with the sql dump you want to load

/usr/local/mysql/bin/mysql --user=root -p

create database mydatabasename default character set utf8;

use mydatabasename;

source mydatabasedump.sql;

show tables;

Converting mysql db to unicode

mysqldump --user=username --password=password --default-character-set=latin1 --skip-set-charset dbname > dump.sql
chgrep latin1 utf8 dump.sql (OR) sed -r 's/latin1/utf8/g' dump.sql > dump_utf.sql
mysql --user=username --password=password --execute="DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql --user=username --password=password --default-character-set=utf8 dbname < dump.sql

Reset mysql password to old style

SET PASSWORD FOR user@localhost = OLD_PASSWORD('password');
« Newer Snippets
Older Snippets »
Showing 21-40 of 61 total