Archive

Articles taggués ‘database’

MySQL – Optimisation

31/01/2024 Comments off

L’optimisation au niveau de MySQL passe par trois composants, à savoir :

  • Optimisation du serveur MySQL
  • Optimisation de la base de données
  • Optimisation des requêtes Lire la suite…

Convert apache HTTP combined logs into SQL (and import it into a mysql database eventually)

28/01/2024 Comments off

source: snippets.dzone.com

you need to extract the data in your http server log files and put it in a database to query it with your usual tools using SQL. this perl script does just this.

it was hard to find it, that’s why i put it here.

#!/usr/bin/perl -w
# Written by Aaron Jenson.
# Original source: http://www.visualprose.com/software.php
# Updated to work under Perl 5.6.1 by Edward Rudd
# Updated 24 march 2007 by Slim Amamou <slim.amamou@alpha-studios.com>
#  - output SQL with the option '--sql'
#  - added SQL create table script to the HELP
#
#  NOTE : you need the TimeDate library (http://search.cpan.org/dist/TimeDate/)
# Lire la suite...

MySQL show users – how to show the users in a MySQL database

26/01/2024 Comments off

MySQL

To show/list the users in a MySQL database, first log into your MySQL server as an administrative user, then run this MySQL query:

select * from mysql.user;

This MySQL query shows a large listing of MySQL user information, including user permission information, so you may want to trim down some of the fields to display. You can get a listing of the fields in the mysql.user table by running this command:

desc mysql.user;

Lire la suite…

Categories: Bases de données Tags: ,

MySQL – Chargement d’un fichier texte dans une table

25/01/2024 Comments off

Pour charger une fichier texte défini comme suit :

$ tail /home/user1/test.txt
   'nom1',1,9
   'nom2',2,3
   'nom3',3,54
   'nom4',4,2
   'nom5',5,9

Dans une table définie comme suit :

CREATE TABLE chargertest (
                cle_prim int(11) NOT NULL auto_increment,
                nom varchar(20),
                x integer,
                y integer,
                z timestamp(14),
                Constraint pk_chargertest PRIMARY KEY  (cle_prim)
);

A noter que le champ ‘z’ n’est pas défini au niveau du fichier texte et que le séparateur utilisé est ‘,’.

mysql> load data infile '/home/user1/test.txt' into table chargertest fields terminated by ',' (nom,x,y);

 

Categories: Bases de données Tags: ,

MySQL – Supprimer des doublons dans une table

19/01/2024 Comments off

Pour supprimer des doublons au niveau d’une table donnée définie comme suit :

CREATE TABLE IF NOT EXISTS TabTest (
           cle_prim integer(4) NOT NULL auto_increment,
           x integer,
           y integer,
           z integer,
           Constraint pk_Tab_test PRIMARY KEY  (cle_prim)
);

Il faut commencer par fixer les champs relatifs au doublons (dans notre cas les champs x et y):

mysql> select * from TabTest;
+----------+------+------+------+
| cle_prim | x    | y    | z    |
+----------+------+------+------+
|        1 |    1 |    2 |    3 |
|        2 |    1 |    2 |    3 |
|        3 |    1 |    5 |    4 |
|        4 |    1 |    6 |    4 |
+----------+------+------+------+
4 rows in set (0.00 sec)

Pour supprimer les doublons au niveau des champs x et y lancer la commande :

ALTER IGNORE TABLE  TabTest ADD UNIQUE INDEX(x,y);

 

Categories: Bases de données Tags: ,