* To start mysql server:
# /etc/init.d/mysql start
* To stop mysql server:
# /etc/init.d/mysql stop
* To restart mysql server
# /etc/init.d/mysql restart
* To start mysql server:
# /etc/init.d/mysql start
* To stop mysql server:
# /etc/init.d/mysql stop
* To restart mysql server
# /etc/init.d/mysql restart
Met sh database automatisch terug zetten.
Maak een sh bestand aan
vim resetDB-shell
Inhoud ervan is hier
#!/bin/sh
sudo mysql -hlocalhost -pwachtwoord -uroot –force -e “DROP DATABASE eEchoDB”
sudo mysql -hlocalhost -pwachtwoord -uroot –force < eEchoDB_20080429_1242.sql
Maak het uitvoerbaar
chmod -R 775 resetDB-shell
run
./resetDB-shell
http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly […]
CREATE INDEX is mapped to an ALTER TABLE statement to create indexes. See Section 12.1.2, “ALTER TABLE Syntax”. CREATE INDEX cannot be used to create a PRIMARY KEY; use ALTER TABLE instead. For more information about indexes, see Section 7.4.5, “How MySQL Uses Indexes”.
http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
CREATE UNIQUE INDEX keyword ON `eEcho`.`keyword` (keyword(128));
http://dev.mysql.com/doc/refman/5.0/en/create-index.html
http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html
BETWEEN … AND … Check whether a value is within a range of values
COALESCE() Return the first non-NULL argument
<=> NULL-safe equal to operator
= Equal operator
>= Greater than or equal operator
> Greater than operator
GREATEST() Return the largest argument
IN() Check whether a value is within a set of values
INTERVAL() Return the index of the argument that is […]
DATETIME, DATE, and TIMESTAMP Types
http://dev.mysql.com/doc/refman/5.0/en/datetime.html
Problems Using DATE Columns ( datetime mysql compare )
http://dev.mysql.com/doc/refman/5.0/en/using-date.html
Date and Time Functions
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
http://code.google.com/apis/base/
What is the Google Base data API?
The Google Base data API enables developers to :
* query Google Base data to create applications and mashups.
* input and manage Google Base items programmatically.
*
Developer’s Guide
[…]
http://dev.mysql.com/doc/refman/5.0/en/row-subqueries.html
The discussion to this point has been of scalar or column subqueries; that is, subqueries that return a single value or a column of values. A row subquery is a subquery variant that returns a single row and can thus return more than one column value. Here are two examples:
SELECT * FROM t1 WHERE (1,2) […]
http://dev.mysql.com/doc/refman/5.0/en/subqueries.html
Subquery is nested voorbeeld:
SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2);
They allow queries that are structured so that it is possible to isolate each part of a statement.
They provide alternative ways to perform operations that would otherwise require complex joins […]
- Maak een nieuwe project aan. / File / New project / Java Project /
- Geef een naam voor de project, klik “Next”
- In volgende venster /tab Libraries/ klik op de knop “Add externeal JARS”
- Blader naar de map waar mysql-connector-java-X.X.X -bin.jar zich bevind en selecteer hem. “OK” […]
Met sqlite kan een database geëxporteerd worden structuur + populatie. (.sql format )
http://sqlitebrowser.sourceforge.net/
Deze toepassing is platform onafhankelijk.
- Download toepassing.
- Run zonder installatie
- Blader naar Sqlite database
- Selecteer tabellen die geëxporteerd moeten worden
- Kies sql als formaat.
- Open deze (.sql ) bestand met tekst editor (zoals kladblok, geditor, ezv)
- Kies opslaan als
- Kies onderaan codering […]
Om server te installeren
$ sudo apt-get install mysql-server
client om tabellen, users, backup, options van de mysql server in GUI te configureren (DD)
$ sudo apt-get install mysql-admin
client om gegevens te aanpassen (inport export ezv. ook SQL ref ingebouwd DM)
$ sudo apt-get install mysql-query-browser
Probleem
Weergeven beperkte aantal records van mysql table.
Oplossing
Gebruik LIMIT op het eind van de sql opdracht
Voorbeeld
SELECT * FROM tbl_test LIMIT 10, 10
Dus selecteer alles van de tbl_test. Start vanaf de record nummer 10 en haal 10 achtervolgde records.
of
UPDATE tbl_test SET prijs=’50′ LIMIT 1
Opmerking: update met limit van 1 gaat veel rapper
In sql server
http://msmvps.com/blogs/pauldomag/archive/2006/04/10/90330.aspx
Full-text searching (zoeken in mysql)
Probleem
moet gezocht worden in meerdere velden tegelijkertijd in grootte database bestanden.
Oplossing
gebruik Full-text searching van MySQL.
Om index toe te voegen
ALTER TABLE some_tbl ADD FULLTEXT (body)
ALTER TABLE some_tbl ADD FULLTEXT (title,body)
(voor iedere index die gezocht moet worden maak een aparte fulltext sleutel)
Als een “GROUP BY domein ORDER BY ci DESC ” […]
MySQL Database Backups
Omdat mysql tabellen worden in bestanden bewaard het is gemakkelijk om backup van te maken.
Gebruik FLUSH TABLES om te zorgen dat niets geschreven wordt tijdens kopiëren.
Om sql kopie te nemen gebruik SELECT INTO … OUTFILE. Het is niet mogelijk om dergelijke bestand iets toe te voegen, het wordt iedere keer overgeschreven. Zie ook […]
Probleem
U wilt met een sql opdracht de inhoud van de meerdere tabellen in een tabel toevoegen.
Oplossing
Gebruik INSERT SELECT van mysql. (
INSERT [LOW_PRIORITY] [IGNORE] [INTO] tbl_name [(column_list)]
SELECT …
)
Voorbeeld
INSERT INTO eecho_sites.tbl_zoekwoorden (eecho_sites.tbl_zoekwoorden.zoekwoord)
SELECT CONCAT(24multimedia.tbl_ondersubcategorie.ondersubcategorie_naam, 24multimedia.tbl_ondersubcategorie.subcategorie_naam, 24multimedia.tbl_ondersubcategorie.categorie_naam)
FROM 24multimedia.tbl_ondersubcategorie
Of met ignore key
INSERT IGNORE INTO eecho_sites.tbl_zoekwoorden (eecho_sites.tbl_zoekwoorden.zoekwoord)
SELECT gids.tbl_pagina.ondersubcategorie_naam
FROM gids.tbl_pagina WHERE ondersubcategorie_naam “
Probleem
U wilt een query resultaat converteren in xml.
Oplossing
Gebruik mysql parameters.
Voorbeeld
% mysql -e "SELECT * FROM limbs WHERE legs=0" uw_database
+————+——+——+
| thing | legs | arms |
+————+——+——+
| squid | 0 | 10 |
| octopus | 0 | 8 |
| fish | 0 | 0 |
| phonograph | 0 | 1 |
+————+——+——+
% mysql -X -e "SELECT * FROM […]
Probleem
U wilt een query resultaat converteren in html.
Oplossing
Gebruik mysql parameters.
Voorbeeld
% mysql -e "SELECT * FROM limbs WHERE legs=0" uw_database
+————+——+——+
| thing | legs | arms |
+————+——+——+
| squid | 0 | 10 |
| octopus | 0 | 8 |
| fish | 0 | 0 |
| phonograph | 0 | 1 |
+————+——+——+
% mysql -H -e "SELECT * […]
Probleem
U wilt een mysql resultaat weergeven of opslaan met verschillende scheiding tekens. Om deze resultaat leesbaarder te maken.
Oplossing
Gebruik mysql parameters.
Voorbeeld
% mysql uw_database < inputfile | sed -e "s/ TAB /:/g" > outputfile
% mysql uw_database < inputfile | tr " TAB " ":" > outputfile
% mysql uw_database < inputfile | tr “\011″ “:” […]
Probleem
U wilt query output (resultaat) op het scherm, in een bestand, in een programma weergeven/afhandelen.
Oplossing
Redirect mysql output of gebruik pipe
Voorbeeld
Mysql output (resultaat) op het scherm afdrukken.
mysql> SELECT * FROM limbs;
+————–+——+——+
| thing | legs | arms |
+————–+——+——+
| human | 2 | 2 |
| insect | 6 | 0 |
| squid | 0 | 10 |
| […]