Archive

Articles taggués ‘MySQL’

Cron Job Tutorial: Crontab Scheduling Syntax and Script Example

29/01/2024 Comments off

source: Devshed

Crontabs is very useful when doing website maintenance. You can use this feature for the following purposes:

  1. Deleting all files in a certain folder at regular intervals. If you accept user-uploaded files, then eventually it will clog your web hosting server. If you do not regularly delete these files, they will consume a lot of disk space and can slow down your website.
  2. Deleting files of a specific type at regular intervals. You can also choose to delete files of a specific type, instead of deleting all of the files in the folder. If you have PHP, HTML and MP3 files together inside the folder, you can delete only the MP3 files.
  3. Regularly backing up your MySQL database. This is one of the most important webmaster tasks. By using crontabs or the cron job feature, you can create a PHP script that will back up a selected MySQL database, and have it execute automatically executed at a specific, regular interval (e.g monthly, yearly, etc).

This tutorial will focus on creating a cron PHP script application, then configuring your cron hosting feature to execute these scripts automatically. Lire la suite…

Categories: Système Tags: , , ,

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 <[email protected]>
#  - 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: ,