Search posterous

Search all posts and users. Type a name, type a favorite song title, whatever! See what comes up.
  

More posterous blogs











More recommended blogs »

Here are posterous posts filed under mysql...

niels says...

A little while ago I was tasked with migrating about hundred Trac instances from SQLite to MySQL. Unfortunately SQLites schema definitions is not compatible with MySQL. So I had to write some scripts to handle it. After a little bit of experimenting everything worked perfectly.

The Strategy I employed was like this:

  1. Make a dump of a default MySQL Trac db schema.
  2. Make a dump of the Trac SQLite database
  3. Remove db schema definitions from the SQLite dump
  4. Concatenate the MySQL and SQLite dumps
  5. Load data into MySQL
  6. Edit Trac's database settings to use MySQL
  7. Do a trac-admin upgrade

Here is the shell script I made:



MYSQL_USER=username
MYSQL_PSWD=password

SQLITECMD=sqlite3
TRACBASE=/path/to/tracreps


# loop through all trac instances in tracreps
for d in $( ls $TRACBASE )
do
if [ -d "$TRACBASE/$d" ]; then
echo $d
TRACNAME=$d

# create database in mysql
echo "creating database for $TRACNAME..."
mysqladmin --user $MYSQL_USER -p$MYSQL_PSWD create $TRACNAME

# dump sqlite db structure + data
echo "dumping data from sqlite..."
$SQLITECMD $TRACBASE/$TRACNAME/db/trac.db .dump > trac.sqlite.sql

# remove database definitions from dump using a custom python script
echo "cleaning database definition from dump..."
`./cleansql.py < trac.sqlite.sql > trac.sqlite.sql.dataonly`

# concatenate mysql database definitions and sqlite data
cat trac.mysql.sql trac.sqlite.sql.dataonly > trac.sql

echo "loading data into mysql..."
mysql --user $MYSQL_USER -p$MYSQL_PSWD --default_character_set utf8 $TRACNAME < trac.sql

# edit database connection string in trac.ini
sed -i "s?sqlite:db/trac.db?mysql://$MYSQL_USER:$MYSQL_PSWD@localhost:3306/$TRACNAME?" $TRACBASE/$TRACNAME/conf/trac.ini

echo "upgrading mysql database..."
trac-admin $TRACBASE/$TRACNAME upgrade --no-backup


To remove schema definitions from the sqlite dump and fix some incompatibilities I made this python script referenced above as cleansql.py:



#!/usr/bin/env python

import sys
import re

file = sys.stdin.read()
file = re.sub(r'(CREATE (TABLE|INDEX)[^;]*|COMMIT|BEGIN TRANSACTION);', '', file)
file = re.sub(r'INSERT INTO "([^"]+)"', lambda m: 'INSERT INTO `%s`' % m.groups(1), file)
# fix sql for reports
file = re.sub(r'CAST\((.+) AS int\)', lambda m: 'CAST(%s AS signed)' % m.groups(1), file)

sys.stdout.write(file)


And that's it. I hope this will benefit someone tasked with the same job.

Filed under: migration, mysql, script, shell, sqlite, trac

varunbansal says...

The following code snippet in SQL is occasionally used by me and I tend to forget the basic syntax or the same.

So here it is, just for reference for future use.

How to backup database in mysql:

Mysqldump –u username –p database_name > dump.sql

Filed under: mysql

fotis says...

I'll try to make it as simple and fast as i can, to help you out with this awkward installation procedure

There is always the MAMP Solution (http://mamp.info), which i know it's pretty cool, but a former linux guy like me can't compromise, plus, current version of MAMP (up to today at least) doesn't include PHP 5.3.0, which i really needed to install, in order to start porting my huge web projects. The basic PHP 5.3.0 features/changes i wanted to work with were namespaces and some deprecated functions (of course there are others, but too minor to even mention). Installin by compiling the source was one-way solution for me, and it reminded me of back in the day i was always tweaking my linux box.

Note: I cheated: I installed a binary version of MySQL because of the neat auto-start features and the "System Preferences" PrefPane. You can find MySQL in this address: http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg Of course, if you want, you can always switch to source distribution and proceed with a simple configure, make, make install (configure options are up to you)

So, i started by downloading the source code for Apache and PHP. First things first: Apache web server

You can download the source code in the following url: http://httpd.apache.org/download.cgi . The file you downloaded looks something like httpd-2.2.14.tar.bz2 so you'd probably want to untar it by using in the Terminal

 bzip2 -cd httpd-2.2.14.tar.bz2 | tar x

After that, you enter the dir, and start configuring by using the following command:

./configure --prefix=/usr/local --enable-mods-shared=all --enable-cache --enable-mem-cache --enable-mime-magic --enable-headers --enable-ssl --enable-dav --enable-suexec --enable-vhost-alias --enable-rewrite --enable-so --with-sslport=443

The configure options are up to you and you can edit/add more by using 

 ./configure --help

After the configure process is done, we can run

make
 make install

Now we have apache installed into /usr/local so we can start the server by running

 /usr/local/bin/apachectl -k start

Same procedure for PHP. Download PHP 5.3.0 using this address http://www.php.net/downloads.php#v5 and select the "Complete Source Code" section. You'll probably end up with an archive that looks like php-5.3.0.tar.bz2

Untar it, enter the directory and DO NOTHING! That's because you can't just run configure by using a simple configure command. Let me be more specific on that:

PHP need some libraries. Example if you want to configure it using the --with-readline option (if your scripts need the readline library), or if you do extensive use of XML like me, you can't just configure it without installing the libraries. Linux users have the priviledge of downloading, installing etc. Mac users on the other hand, have to use the MacPorts tool (http://www.macports.org). 

Download and install MacPorts by using the dmg provided. MacPorts is installed into /opt/local so in terminal you can run the command

/opt/local/bin/port search libxml2

The program outputs results that are based on your search (here, is libxml2), you pick the title that matches your needs and you run

 /opt/local/bin/port install libxml2

Now that you have installed all the libraries you need, you can run the configure command by using this (of course you can add/remove options you like/don't like). IMPORTANT: You must include the --with-config-file-path directive beacuse otherwise you won't be able to use php.ini, Be careful on the paths that are related to apache (apache, apxs):

./configure --prefix=/usr/local --with-apxs2=/usr/local/bin/apxs  --with-config-file-path=/usr/local/lib --with-bz2 --with-zlib=/opt/local --enable-ftp --with-gd --enable-gd-native-ttf --with-mcrypt --with-mysql --with-readline=/opt/local --enable-soap --enable-zip --enable-bcmath --enable-calendar --enable-exif --enable-magic-quotes --enable-mbstring --enable-sockets --enable-wddx --enable-zend-multibyte --with-jpeg-dir=/usr/X11R6 --with-png-dir=/usr/X11R6 --with-pdo-mysql=/usr/local/mysql --with-curl=/opt/local --enable-mbregex --with-libxml-dir=/opt/local --with-gettext=/opt/local --with-iconv-dir=/opt/local --with-freetype-dir=/usr/X11R6

 

The jpeg, freetype and png libraries that came with your mac, are not only compatible, but it's recommended to use them, that's why in some of the options above are using the /usr/X11R6 path.

If you've correctly installed by using MacPorts all the libraries you need the configure process ends normally and you'll se the "Creating files" section

If you run make now, you'll probably get the following error (If not, WOW! you can proceed :D ):

Undefined symbols for architecture i386:

  "_xmlTextReaderSchemaValidate", referenced from:
      _zim_xmlreader_setSchema in php_xmlreader.o
  "_xmlTextReaderSetup", referenced from:
      _zim_xmlreader_XML in php_xmlreader.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
Undefined symbols for architecture x86_64:
  "_xmlTextReaderSchemaValidate", referenced from:
      _zim_xmlreader_setSchema in php_xmlreader.o
  "_xmlTextReaderSetup", referenced from:
      _zim_xmlreader_XML in php_xmlreader.o
ld: symbol(s) not found for architecture x86_64

It may seem weird and difficult to cure, but it's not actually. The makefile generated by the configure process contains some wrong variables and all you have to do is open it, go straight to line that contains the following line:

MH_BUNDLE_FLAGS = -bundle -bundle_loader /usr/sbin/httpd -L/usr/lib\
 -L/usr/lib -laprutil-1 -lsqlite3 -lexpat -liconv -L/usr/lib -lapr-1 -lpthread	

Delete the duplicate -L/usr/lib nd before every occurence of the -L/usr/lib add -L/opt/local/lib as described in this blog post: http://blog.yimingliu.com/2009/02/24/missing-library-symbols-while-compiling-php-528/

so you'll end up with something that looks like that:

MH_BUNDLE_FLAGS = -bundle -bundle_loader /usr/sbin/httpd -L/opt/local/lib \
 -L/usr/lib -laprutil-1 -lsqlite3 -lexpat -liconv -L/opt/local/lib -L/usr/lib -lapr-1 -lpthread	
	You are now ready to hit make again. If another error occures, it means you messed up this line. Be sure to have as many -L/opt/local/lib occurences as -L/usr/lib. You can also add two occurences of -L/usr/local/lib
At this point, make should give you a clean, fresh build of PHP 5.3.0. You may now make install and start tweaking your httpd.conf located in /usr/local/conf
You must add the line
LoadModule php5_module modules/libphp5.so 
You must add the line
AddType application/x-httpd-php .php
And also tweak the DirectoryIndex by adding index.php
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

If you now try to restart (or start) apache for the first time. you'll probably face another error that has to do with some undefined symbol "_iconv" or something related to libiconv.2.dylib

This is the second fix you have to take care: You open up envvars file inside the apache bin directory. (In our case: /usr/local/bin/envvars) and tweak this line

DYLD_LIBRARY_PATH="/usr/local/lib:/usr/lib:$DYLD_LIBRARY_PATH"

To look something like that, which includes your macports libraries

DYLD_LIBRARY_PATH="/opt/local/lib:/usr/local/lib:/usr/lib:$DYLD_LIBRARY_PATH"

There you go! You are now ready to start your apache web server (/usr/local/bin/apachectl -k start) and work on your PHP 5.3.0 projects.

Have fun!

 

 

 

Filed under: Apache, MySQL, PHP, Server

was only a matter of time for the mysql db to be in the cloud properly.

Amazon RDS provides a fully featured MySQL database, so the code, applications, and tools that you use today with your existing MySQL databases work in Amazon RDS without modification. The service automatically handles common database administration tasks, such as setup and provisioning, patch management, and backup. You also have the flexibility to scale the compute and storage resources associated with your database instance through a simple API call. Like all AWS infrastructure services, Amazon RDS is easy to deploy and simple to manage. Here are some highlights for Amazon RDS

can i get a 'yay' - now if only they had custom versions of a really really lightweight hypertuned OS image.  like a really custom nginx, memcached, php, zend image the dream would be complete.  really good news thou to have something like this now in the cloud. 

Filed under: amazon, database, mysql, rds

sinantr says...

date_format(date, '%d-%m-%Y %H:%i:%s') AS date

Filed under: mysql

ssk says...

Here is the code.
import MySQLdb
import simplejson as json
db = MySQLdb.connect(host='xxx', user='xx', passwd='xx', db='xxx')
cursor = db.cursor()
def getSQLJSON(hostName,dbName,id,pw,sql):
global db,cursor
resultArray =[]
cursor.execute(sql)
tableDescription = cursor.description
result = cursor.fetchall()
for e in result:
resultRaw ={}
columnIndex =0
for ee in e:
vcoulumnName = tableDescription [columnIndex][0]
resultRaw[coulumnName]=ee
columnIndex +=1
resultArray.append(resultRaw)
jsonResult = json.dumps(resultArray, separators=(',',':'))
return jsonResult

mysql の出力を JSON 形式へ?

Filed under: json, mysql, python

nikan says...


[full-time] joomla και cs-cart Developer at Microchip. Ευβοϊκή ΕΠΕ

Posted:

Location: Χαλκίδα
URL: http://www.e-microchip.gr

Description:

Μονιμη εργασια σε υπαρχοντα project και δημιουργια νεων κυριως πανω σε joomla ( με magento) και cs-cart.

Apply to this job

[freelance] PHP / MySQL / Ajax developer at Kosmopolis Inc LLC

Posted:

Location: Παντού
URL: http://netenberg.com

Description:

Από εταιρεία server side λογισμικού με διεθνή πελατεία ζητούνται 2 έμπειροι προγραμματιστές PHP/MySQL για δουλειά από το σπίτι. Πολύ καλή αμοιβή. Πτυχία αδιάφορα, ενδιαφερόμαστε για ανθρώπους που προγραμματίζουν καθαρό κώδικα, με συνέπεια και πάθος, από αγάπη για το αντικείμενο.

Apply to this job

Filed under: developer, joomla, mysql, php, web

schmatz says...

CMS steht für "Content Management System", man kann auch Redaktionssystem dazu sagen. In der Regel versteht man unter CMS ein Web-Content Management System (kurz WCMS) - es gibt aber auch CMS für Verlage, mit denen z.B. Zeitungen gemacht werden.

Mit einem WCMS werden wie Sie sicher schon erraten  haben, Websites gewartet. Der Vorteil von WCMS ist, dass Sie ohne HTML-/CSS-Kenntnisse neue Inhalte auf eine Website stellen können oder bestehende Inhalte bearbeiten oder löschen können. Ein weiterer Vorteil ist, dass man bei WCMS leicht neue Links in der Navigation hinzufügen kann ohne wie es bei "handgeschriebenen" Websites notwendig wäre, jede einzelne Seite dafür bearbeiten zu müssen.

Die Inhalte werden bei WCMS nicht in HTML-Seiten gespeichert sondern in Datenbanken - meistens in MySQL-Datenbanken (was das ist können Sie hier nachlesen: http://schmatz.posterous.com/mysql-was-ist-das). Wenn nun jemand auf eine mit einem WCMS erstellte Website zugreift so wird eine Datei in einer Skriptsprache (z.B. PHP oder ASP) aufgerufen. Diese Datei "holt" dann die Inhalte der Website aus der Datenbank, verknüpft sie mit der Seitenvorlage (engl. "Template") und gibt sie als HTML-Datei an den Browser aus. Man spricht dabei von einer "dynamisch generierten" Website - im Gegensatz zu "statischen" Websites, bei denen die HTML-Dateien sozusagen "fix und fertig" auf dem Server liegen.

Heutzutage sind serverseitige WCMS der Standard. Das bedeutet, dass das WCMS auf einem Webserver liegt und dass Sie die Inhalte Ihrer Website über jeden Webbrowser bearbeiten können. Sie brauchen also kein spezielles Programm installieren.

Technisch gesehen ist auch jedes Weblog-System ein WCMS, meistens spricht man jedoch bei WCMS von solchen Systemen, die mehr als nur das Veröffentlichen von aktuellen Beiträgen erlauben, also zum Beispiel "fixe" Seiten, Formulare, Gästebücher, Umfragen, Mitgliederbereiche und vieles andere mehr.

Wenn derartige Funktionen nicht im CMS selbst enthalten sind gibt es meistens Erweiterungen (engl. "Plugins") dafür.

Bekannte Open-Source-WCMS wären Joomla! - http://www.joomla.de/ , Drupal - http://www.drupal.org/ , typoLIGHT - http://www.typolight.org/ - oder TYPO3 - http://www.typo3.org/ . Die Funktionalitäten des Weblog-Systems Wordpress - http://www.wordpress.org/  sind mittlerweile so umfangreich, dass viele auch Wordpress als WCMS bezeichnen.

Der Nachteil von WCMS ist, dass es natürlich eine gewisse Zeit braucht, bis der Webserver so eine Seite dynamisch generiert. Für die meisten Websites von Privatpersonen, Vereinen, Klein- und Mittelbetrieben ist das jedoch heutzutage kein Problem mehr, da die Server der meisten Webspace-Provider ausreichend Rechenpower und Arbeitsspeicher haben. Früher hat man sich öfters so beholfen, dass man die Website auf einem öffentlich nicht zugänglichen Server dynamisch generiert hat und dann mit einem speziellen Programm "gerendert" hat. Das bedeutet, dass man eine Kopie der Website als statische Website auf einen öffentlich zugänglichen Webserver gespielt hat. Das zum Google-Imperium gehörende Weblog-System Blogger - http://www.blogger.com - bietet auch heute noch die Möglichkeit, eine statische Kopie eines Weblogs mittels FTP automatisch auf einen anderen Webspace zu spielen.

Filed under: CMS, Drupal, Joomla, MySQL, Open Source, Typo3, Typolight, WCMS, Web 2.0, Wordpress

schmatz says...

MySQL ist ein relationales Datenbankverwaltungssystem, das als Open Source-Software zur Verfügung steht.

Was Open Source bedeutet werde ich Ihnen später einmal erklären. Für Sie wird es in erster Linie bedeuten, dass es kostenlos zur Verfügung steht.

Viele Webspace-Provider bieten in ihren Paketen neben Webspace auch eine MySQL-Datenbank oder mehrere MySQL-Datenbank an.

Wenn Sie ein Weblog führen, eine Website mit Content Management System (CMS), einen Webshop oder irgendeine andere Website, bei der Sie nicht selbst jede einzelne Seite mit HTML schreiben möchten, führen möchten, so werden Sie eine Datenbank brauchen. Die meisten Systeme, die für Privatpersonen, Vereine, Klein- und Mittelbetriebe heutzutage interessant sind, verwenden dafür MySQL-Datenbanken.

Nähere Informationen zu MySQL finden Sie in der Wikipedia unter http://de.wikipedia.org/wiki/MySQL sowie natürlich auf der offiziellen MySQL-Website http://www.mysql.de/ .

Filed under: Datenbank, MySQL, Open Source, Web 2.0

hdknr says...

imporError

(jail)hdknr@mailjail:~/.ve/jail/src/djpostfix/djpostfix$ python
Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "__init__.py", line 19, in <module>

       File "/home/hdknr/.ve/jail/lib/python2.5/site-packages/MySQL_python-1.2.3c1-py2.5-linux-i686.egg/_mysql.py", line 7, in <module>
  File "/home/hdknr/.ve/jail/lib/python2.5/site-packages/MySQL_python-1.2.3c1-py2.5-linux-i686.egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory

削除

(jail)hdknr@mailjail:~/.ve/jail/lib/python2.5/site-packages$ rm MySQL_python-1.2.3c1-py2.5-linux-i686.egg

aptで入れなおす

(jail)hdknr@mailjail:~/.ve/jail/lib/python2.5/site-packages$ sudo aptitude install python-mysqldb
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了       
以下の新規パッケージがインストールされます:
  python-mysqldb
更新: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
アーカイブ 94.8kB 中 0B を取得する必要があります。展開後に 336kB のディスク領域が新たに消費されます。
拡張状態情報を書き込んでいます... 完了
未選択パッケージ python-mysqldb を選択しています。
(データベースを読み込んでいます ... 現在 78680 個のファイルとディレクトリがインストールされています。)
(.../python-mysqldb_1.2.2-10_i386.deb から) python-mysqldb を展開しています...
python-mysqldb (1.2.2-10) を設定しています ...
python-support のトリガを処理しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了       
タスクの記述を読み込んでいます... 完了 

OK

(jail)hdknr@mailjail:~$ python
Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>
(jail)hdknr@mailjail:~$

(jail)hdknr@mailjail:~$ pip install MySQL-python
Requirement already satisfied: MySQL-python in /usr/lib/pymodules/python2.5
Installing collected packages: MySQL-python
Successfully installed MySQL-python

Filed under: easy_install, MySQL, pip, Python, virtualenv