Arkiv

Inlägg taggade ‘mysql’

Hitta och ersätt i wordpress inlägg

april 10th, 2010 admin Inga kommentarer

Tänkte bara skriva upp en liten snippet för att hitta och ersätta saker i wordpress inlägg.

Snippet:

UPDATE wordpress SET wp_posts = replace(wp_posts,”wordpress 3.0″,”wordpress 3.1″);

Categories: GSOC Taggar: , , ,

MySQL hints

februari 10th, 2010 admin Inga kommentarer

Måste ta och skriva ner vissa saker ibland annars glömmer jag det, och varför inte skriva dom här?

För att replacea någon text i mysql använder jag denna:

UPDATE posts SET post_content = replace(post_content,”arf”,”")

Categories: GSOC Taggar: , , , ,

Optimera MySQL

december 23rd, 2009 admin Inga kommentarer

Tänkte tipsa om ännu ett verktyg för att optimera mysql och hålla ordning på allt, och det är tuning-primer.sh

Du kan ladda hem scriptet här:

http://www.day32.com/MySQL/tuning-primer.sh

Här nedan kan du se ett exempel på resultatet från tuning-primer.sh:

— MYSQL PERFORMANCE TUNING PRIMER –
– By: Matthew Montgomery -

MySQL Version 5.0.51a-24+lenny2-log i486

Uptime = 0 days 0 hrs 0 min 14 sec
Avg. qps = 73
Total Questions = 1028
Threads Connected = 2

Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations

To find out more information on how each of these
runtime variables effects performance visit:

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html

Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL’s Enterprise Monitoring and Advisory Service

SLOW QUERIES
The slow query log is enabled.
Current long_query_time = 2 sec.
You have 0 out of 1124 that take longer than 2 sec. to complete
Your long_query_time seems to be fine

BINARY UPDATE LOG
The binary update log is NOT enabled.
You will not be able to do point in time recovery
See http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery.html

WORKER THREADS
Current thread_cache_size = 8
Current threads_cached = 1
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 125
Current threads_connected = 1
Historic max_used_connections = 2
The number of used connections is 1% of the configured maximum.
You are using less than 10% of your configured max_connections.
Lowering max_connections could help to avoid an over-allocation of memory
See ”MEMORY USAGE” section to make sure you are not over-allocating

No InnoDB Support Enabled!

MEMORY USAGE
Max Memory Ever Allocated : 71 M
Configured Max Per-thread Buffers : 328 M
Configured Max Global Buffers : 66 M
Configured Max Memory Limit : 394 M
Physical Memory : 1011 M
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 14 M
Current key_buffer_size = 16 M
Key cache miss rate is 1 : 13
Key buffer free ratio = 87 %
Your key_buffer_size seems to be fine

QUERY CACHE
Query cache is enabled
Current query_cache_size = 40 M
Current query_cache_used = 388 K
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = .94 %
Current query_cache_min_res_unit = 4 K
Your query_cache_size seems to be too high.
Perhaps you can use these resources elsewhere
MySQL won’t cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 256 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 132.00 K
You have had 0 queries where a join could not use an index properly
Your joins seem to be using indexes properly

OPEN FILES LIMIT
Current open_files_limit = 4247 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_cache value = 2056 tables
You have a total of 673 tables
You have 673 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 32 M
Of 208 temp tables, 16% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Created disk tmp tables ratio seems fine

TABLE SCANS
Current read_buffer_size = 128 K
Current table scan ratio = 7 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 0 : 2056
Your table locking seems to be fine

Categories: GSOC Taggar: , , , , , , ,

MySQL ta bort alla likadana poster

juni 23rd, 2009 admin Inga kommentarer

För att enkelt ta bort likadana poster i MySQL följ guiden nedan:

mysql> use XXX;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> create table ny_posts AS select * from posts where 1 group by post_title;
Query OK, 1674 rows affected (0.11 sec)
Records: 1674 Duplicates: 0 Warnings: 0

mysql> drop table posts;
Query OK, 0 rows affected (0.01 sec)

mysql> rename table ny_posts to posts;
Query OK, 0 rows affected (0.00 sec)

mysql>

Categories: GSOC, Webb Taggar: , ,

Starta om linux på natten

juni 17th, 2009 admin Inga kommentarer

Jag har lite diffusa problem med minnesanvändningen av min VPS just nu, och en temporär(!) lösning kan vara att starta om servern en gång mitt i natten, det har löst det tillfälligt för mig, medans jag optimerar apache & mysql så får det vara så här.

Logga in som root och kör ‘crontab -e’ och lägg sedan in detta för att starta om en gÃ¥ng varje natt klockan 04:00, all output som kan tänkas komma frÃ¥n den kastas bort.

0 4 * * * shutdown -r now >/dev/null

Åter igen så vill jag poängtera att detta endast är en temporär lösning!

Categories: GSOC Taggar: , , , , ,

Backup mysql html

juni 16th, 2009 admin Inga kommentarer

Ett litet script som tar backup på dina databaser samt html filer, och komprimerar dom efteråt för enkel förvaring.

#!/bin/sh
#backup 0.1 gsoc
#dumps databases and all html
mkdir /root/tools/backups
cd /root/tools/backups
#Databas
mysqldump –all-databases -p | bzip2 -c > backup-`date +”%b_%d_%Y”`.sql.bz2
#HTML
tar –create –bzip2 –file=backup-`date +”%b_%d_%Y”`.tar.bz2 /var/www/sites

Categories: GSOC, Webb Taggar: , , , ,

Optimera MySQL med mysqlcheck

juni 3rd, 2009 admin Inga kommentarer

För att kolla och reparera samt optimera alla mysql databaser så kör detta kommando :

mysqlcheck -u root -p –auto-repair –check –optimize –all-databases

Man kan sedan använda denna i cron för att få denna optimering dagligen.

Relaterade länkar om Optimera MySQL med mysqlcheck

Categories: Internet, Webb Taggar: , , , , ,

Optimera MySQL

maj 27th, 2009 admin Inga kommentarer

Nedan kommer ett verktyg som är perfekt för att optimera sin MySQL.

Installation av MySQLtuner.pl:

wget mysqltuner.pl/mysqltuner.pl.gz
gzip -d mysqltuner.pl.gz
chmod 0700 mysqltuner.pl
./mysqltuner.pl

Exempel på optimering:

XXX:~/tools# ./mysqltuner.pl

>> MySQLTuner 1.0.0 – Major Hayden
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with ‘–help’ for additional options and output filtering
Please enter your MySQL administrative login: —
Please enter your MySQL administrative password:

——– General Statistics ————————————————–
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.51a-24+lenny1
[OK] Operating on 32-bit architecture with less than 2GB RAM

——– Storage Engine Statistics ——————————————-
[--] Status: +Archive -BDB -Federated -InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 15M (Tables: 433)
[!!] Total fragmented tables: 43

——– Performance Metrics ————————————————-
[--] Up for: 2d 3h 40m 22s (1M q [10.118 qps], 83K conn, TX: 97M, RX: 350M)
[--] Reads / Writes: 92% / 8%
[--] Total buffers: 58.0M global + 2.6M per thread (100 max threads)
[OK] Maximum possible memory usage: 320.5M (31% of installed RAM)
[OK] Slow queries: 0% (7/1M)
[OK] Highest usage of available connections: 24% (24/100)
[OK] Key buffer size / total MyISAM indexes: 16.0M/7.1M
[OK] Key buffer hit rate: 99.4% (30M cached / 180K reads)
[OK] Query cache efficiency: 78.5% (1M cached / 1M selects)
[!!] Query cache prunes per day: 57655
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 71K sorts)
[!!] Temporary tables created on disk: 49% (25K on disk / 52K total)
[OK] Thread cache hit rate: 99% (76 created / 83K connections)
[!!] Table cache hit rate: 0% (64 open / 16K opened)
[OK] Open file limit used: 12% (128/1K)
[OK] Table locks acquired immediately: 99% (435K immediate / 435K locks)

——– Recommendations —————————————————–
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
Enable the slow query log to troubleshoot bad queries
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries without LIMIT clauses
Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
query_cache_size (> 16M)
tmp_table_size (> 32M)
max_heap_table_size (> 16M)
table_cache (> 64)

Men då har jag redan ändrat lite för att optimera, men det första man bör göra är att stänga av InnoDB om man inte använder det så har man tjänat ca 100mb i arbetsminne som den tar upp på default.

Lägger också upp en mirror här av mysql optimeraren:
MySQLtuner.pl.gz

Relaterade länkar om Optimera MySQL

Categories: Internet, Webb Taggar: , ,