mysql

install phpMyAdmin

Check for current version
www.phpmyadmin.net

wget https://raw.github.com/panticz/installit/master/install.phpMyAdmin.sh -O - | bash -

#!/bin/bash

URL=http://switch.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.0.8/phpMyAdmin-4.0.8-english.tar.bz2

# set variables
FILE=${URL##*/}

# set target
if [ ! -z $1 ]; then
  TARGET=$1
else
  TARGET=/var/www
fi

# set owner
if [ ! -z $2 ]; then
  WWW_USER=$2
else
  WWW_USER=www-data
fi

# download if not already exists
[ ! -f /tmp/${FILE} ] && wget -nv ${URL} -O /tmp/${FILE}

# backup old phpmyadmin installation
[ -d ${TARGET}/phpMyAdmin/ ] && mv ${TARGET}/phpMyAdmin/ ${TARGET}/phpMyAdmin.backup.$(date "+%F_%T")

# extract
tar -xjf /tmp/${FILE} -C ${TARGET}

# rename directory to simply "phpMyAdmin"
mv ${TARGET}/phpMyAdmin-*/ ${TARGET}/phpMyAdmin/

# change owner
chown ${WWW_USER}:${WWW_USER} -R ${TARGET}/phpMyAdmin/

Configure
cp config.sample.inc.php config.inc.php
vi config.inc.php
$cfg['blowfish_secret'] = 'terceS';

# configure user and db
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'YOUR_DB_USER';
$cfg['Servers'][$i]['password'] = 'YOUR_DB_PASS';
$cfg['Servers'][$i]['host'] = 'YOUR_DB_HOST';

# optionaly you can restrict whitch databases should by showed in phpMyAdmin
$cfg['Servers'][$i]['only_db'] = 'YOUR_DB_NAME';

OPTIONAL

# enable SSL encryption
cat <> ${TARGET}/.htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
EOF

# restrict access
cat <> ${TARGET}/.htaccess
AuthName "Authorized Users Only."
AuthType Basic
AuthUserFile /etc/apache2/htpasswd
Require user YOUR_USER
EOF

# create password file
touch /etc/apache2/htpasswd
htpasswd -b /etc/apache2/htpasswd YOUR_USER YOUR_PASS

# restart apache
/etc/init.d/apache2 restart
1

Connect to MySQL DB

# ubuntu package
sudo apt-get install -y libmysql-java

path: /usr/share/java/mysql-connector-java.jar

# download
wget http://ftp.gwdg.de/pub/misc/mysql/Downloads/Connector-J/mysql-connector-java-5.1.12.tar.gz -P /tmp

# extract
tar xzf /tmp/mysql-connector-java-5.1.12.tar.gz -C /tmp/

# copy to your classpath
cp /tmp/mysql-connector-java-5.1.12/mysql-connector-java-5.1.12-bin.jar ~/NetBeansProjects/classpath/

# Netbeans
add Library / Jar File
select
~/NetBeansProjects/classpath/mysql-connector-java-5.1.12-bin.jar

# create tatabase
create database java;

MySql Tunel

apt-get install mysql-admin
 
# create tunel
ssh root@192.168.1.88 -L 3306:localhost:3306
 
# connect
mysql-admin -u magento -p magento -h 127.0.0.1
 
# Links
http://gss-konstanz.de/8-kerne-und-nen-typ/2007/10/26/windows-als-gastsystem-in-debian-xen/

install Java database (JDBC) driver for MySQL

sudo apt-get install libmysql-java
 
# old, manuall installation
# wget http://ftp.gwdg.de/pub/misc/mysql/Downloads/Connector-J/mysql-connector-java-5.1.6.tar.gz -P /tmp
# tar xzf /tmp/mysql-connector-java-5.1.6.tar.gz -C /tmp
# cp /tmp/mysql-connector-java-5.1.6/mysql-connector-java-5.1.6-bin.jar /opt/gwt-linux/
 
# LINKS
http://packages.ubuntu.com/feisty/libs/libmysql-java

Create GWT MySQLConn project under Netbeans

# HowTo
1. install Netbeans: http://www.panticz.de/install_netbeans
1.1 install http://www.panticz.de/install-GWT4NB
2. install GWT: http://www.panticz.de/install_gwt
3. install MySQL driver: http://www.panticz.de/install_mysql_driver
4.

GWT + MySQL + Netbeans Demo

# INFO
url : jdbc:mysql://localhost:3306/Bible
user: gwt-examples
pass: password
 
# create database and user
mysql -u root -p
create database Bible;
CREATE USER 'gwt-examples' IDENTIFIED BY 'password';
grant all on Bible.* to 'gwt-examples'@'%' identified by "password";
#grant all on Bible.* to 'gwt-examples'@'192.168.1.10' identified by "password";
#grant all on Bible.* to 'gwt-examples'@'localhost' identified by "password";
commit;
quit;
 
# get gwt examples 
cd ${HOME}
svn checkout http://gwt-examples.googlecode.com/svn/trunk/ gwt-examples
 
# fill database
wget http://ken

Install MySql

#!/bin/bash
 
sudo apt-get -y install mysql-server
 
# auto preconfigure password
 
# admin mysql client
audo apt-get -y install mysql-admin
audo apt-get -y install mysql-query-browser

MySQL Queries

-- select 10 random row from table
SELECT column FROM TABLE
ORDER BY rand()
limit 10
 
-- update table (use join)
UPDATE table1
JOIN table2
ON table1.product = table2.a
SET table1.sku = table2.b
--where table1.product = 2138
 
-- view all databases
show databases;
 
-- view tables from database
show tables FROM mysql;
 
-- timestamp 7 days ago
date_sub(curdate(), INTERVAL 7 DAY);
 
-- format date
SELECT TO_CHAR(TIME, 'YYYY-MM-DD HH24:MI') FROM LOG;
 
-- replace first char to upercase
UPDATE customer SET first_name = CONCAT(UPPER(LEFT(first_name, 1)), SUBSTRING(first_name, 2)

Export MySQL Database

Login
mysql -u root -p

Links
phpMyAdmin - phpMyAdmin downloads

GUI
apt-get install -y mysql-admin

Allow access from outsice
sed -i 's|bind-address|#bind-address|g' /etc/mysql/my.cnf
/etc/init.d/mysql restart

Allow access to database magento for user dbo_magento from any host
GRANT ALL PRIVILEGES ON magento.* TO dbo_magento@'%' IDENTIFIED BY 'your_pass'

Links

Syndicate content