Rechercher dans ce blog

lundi 14 décembre 2009

droit automontage / hal / policykit

Pour changer les droits de montage de l'applet places sur enligthenment (openGEU 8.10 par exemple) j'ai modifié

/etc/PolicyKit/PoliciyKit.conf

match user ="nom d'utilisateur qui peut monter les disques" (par défaut c'est root)

Attention si les disques sont dans fstab, ils sont montés au boot. Dans ce cas, bien mettre en rw dans fstab si l'on veut pouvoir écrire sur les volumes.


udev / listes des interfaces

Après un changement de cartes réseau, pour que les ubuntu oublient l'ancienne carte il faut supprimer l'entrée dans

/etc/udev/rules.d/70-persistent.. bla bla network..

Sinon la nouvelle carte se retrouve en eth1 ou plus et la config d'ip fixe est à l'eau...

mercredi 9 décembre 2009

configurer X-server

Pour récupérer le fichier xorg.conf sur les systèmes qui n'en ont pas. Quand X est lancé et tourne correctement, je fais un

#X :1 -configure qui me donne en retour un xorg.conf.new que je peux ensuite customiser.

Pour lister et ajouter des modes j'utilise xrandr

et pour définir des modelines j'utilise : cvt

Je peux coller ensuite les modelines voulus dans le xorg.conf

(ce qui est utile quand la détection dcc du moniteur se fait mal)

Pour les intel915 qu'on trouve sur les P4 j'utilise aussi 915resolution pour patcher à la volée le bios.

Pour généner des modelines il y a aussi : videogen (mais jamais utilisé)

Il y a aussi un script que l'on trouve parfois installé : displayconfig-gtk

---

II. Use xrandr to enable/disable/move/resize multiple outputs

II.1. Basics

Once the configuration file (xorg.conf) is updated, starting the server should enable some outputs by default. Their top-left corners will be at the same part of the image, but their modes will probably be different.

All outputs may be configured through xrandr (or the grandr graphic tool). To see the available outputs, just run xrandr:

  $ xrandr

  Screen 0: minimum 320 x 200, current 1400 x 1050, maximum 2048 x 1152

  VGA-0 disconnected (normal left inverted right x axis y axis)

  DVI-0 disconnected (normal left inverted right x axis y axis)

  LVDS connected 1400x1050+0+0 (normal left inverted right x axis y axis) 0mm x 0mm

   1400x1050 60.2*+

   1280x800 60.0

   1280x768 60.0

   1024x768 60.0 75.0

   800x600 60.3

   640x480 59.9

  S-video disconnected (normal left inverted right x axis y axis)

It shows that this board supports 4 outputs, names VGA-0, DVI-0, LVDS (the internal panel) and S-video (the TV output). Only LVDS is connected and it supports 6 modes at 60 Hz, and one at 75.

The mode marked with a star is the current mode.

The one marked with a plus is the preferred one. Most monitor report a preferred mode to the driver. And the server/driver will generally choose it by default.

II.2. Outputs naming convention

There are no standard naming convention as of today, it just depends on the driver, but it could change in the future.

At least the RadeonHD driver will print out a list of outputs as part of the /var/log/Xorg.0.log file generated by trying to start X. An example of output from the RadeonHD driver is

(II) RADEONHD(0): Output DVI-I_1/digital connected

(II) RADEONHD(0): Output DVI-I_1/analog disconnected

(II) RADEONHD(0): Output TV_7PIN_DIN disconnected

(II) RADEONHD(0): Output DVI-I_2/digital connected

(II) RADEONHD(0): Output DVI-I_2/analog disconnected

Where for example "DVI-I_1/digital" is the name of the digital output of the first DVI port.

For the internal laptop panel, external VGA, external DVI and TV, the drivers currently use:

the Intel driver uses LVDS, VGA, TMDS-1 (TMDS-2, ...), TV

the ATI driver uses LVDS, VGA-0 (VGA-1, ...), DVI-0 (DVI-1, ...), S-video

the RadeonHD driver uses PANEL, VGA_1 (VGA_2, ...), DVI-I_1/digital or DVI-I_1/analog (DVI-I_2/digital or DVI-I_1/analog, ...), TV_7PIN_DIN

the NV driver uses LVDS, VGA0 (VGA1, ...), DVI0 (DVI1, ...), ???

the MGA driver uses ???, VGA (or VGA1, VGA2, ...), DVI (or DVI1, DVI2, ...), ???

the Nouveau driver uses ???, Analog-0 (Analog-1, ...), Digital-0 (Digital-1, ...), ???

When manipulating VGA-0 output properties as below, you should use:

  $ xrandr --output VGA-0 <options>

II.3. Adding/removing heads dynamically

The old days where you had to restart X when plugging a new monitor are gone. With RandR 1.2, you can plug/unplug monitors whenever you want. Running the following line will query all outputs and enable them with their default mode:

  $ xrandr --auto

You may also disable one output using:

  $ xrandr --output LVDS --off

This may be useful for some buggy application that don't support multiple outputs well. Also, due to CRTC limitations (see the Caveats section below), it is often required to disable one output before enabling another since most hardware only support 2 at the same time.

II.4. Changing the mode

With the above xrandr output, you may change the LVDS mode to 1024x768 using:

  $ xrandr --output LVDS --mode 1024x768

The refresh rate may also be changed, either at the same time or independently:

  $ xrandr --output LVDS --mode 1024x768 --rate 75

II.5. Placing outputs in a virtual screen

Randr 1.2 provides the ability to create a large virtual screen and place multiple output in it, either with or without overlapping zones. To reduce memory consumption, drivers will often create a default virtual screen with small dimensions, for instance 1600x1200. Look at the output of xrandr to know your virtual screen dimensions. It would be 2048x1152 if xrandr reports:

  $ xrandr

  Screen 0: minimum 320 x 200, current 1400 x 1050, maximum 2048 x 1152

If you plan to use multiple outputs displaying different zones, you should configure your xorg.conf by adding a Virtual line to subsection Display in the Screen section.

  Section "Screen"

   ...

   SubSection "Display"

   Depth 24

   Virtual 3000 2000

   EndSubSection

  EndSection

Then you place outputs using xrandr and the --right-of/--left-of/--above/--below options. For instance, to place your VGA output virtually-right of your internal panel, run:

  $ xrandr --output VGA --right-of LVDS

Note that hardware and memory limitations may severely restrict the size of your virtual screen, see the Caveats section below.

II.6. Adding new modes

Under some circumstances, some modes might be missing. For instance, if the monitor does not report correct EDID information. Or if the output didn't have a CRTC available at startup because another output was using it and you disabled it in th meantime.

If a mode exist, you may add it to one output with:

  $ xrandr --addmode S-video 800x600

If the mode does not exist, you may first create it by passing a modeline:

  $ xrandr --newmode <ModeLine>

You may create a modeline using the gtf or cvt utility.

III. xorg.conf based configuration

Running xrandr is convenient for dynamic configuration, but it may be annoying if you have to run it after every startup of your X server. Section III.6 summarizes all this by showing an example of modern configuration.

III.1. Per Output Config

Before configuring an output, you need to know how to specify it in the config file. To do so, you may add a Monitor-FOO option to the Device section to identify the monitor section for output FOO. For instance:

  Section "Device"

   Identifier "My Graphic Board"

   ...

   Option "Monitor-LVDS" "Internal Panel"

   Option "Monitor-VGA" "External VGA Monitor"

  EndSection

  Section "Monitor"

   Identifier "Internal Panel"

   ...

  EndSection

  Section "Monitor"

   Identifier "External VGA Monitor"

   ...

  EndSection

Then, all output-specific options should go in the corresponding Monitor section.

III.2. Placing outputs

Add the following line to place one monitor on the right of another one as xrandr --output FOO --right-of BAR would do:

  Section "Monitor"

   Identifier "FOO"

  EndSection

  Section "Monitor"

   Identifier "BAR"

   Option "RightOf" "FOO"

  EndSection

III.3. Changing DPI and DisplaySize

If your monitor size isn't detected correctly and thus generates a wrong DPI, you need to add a DisplaySize option to the corresponding monitor section. For output FOO, use:

  Section "Monitor"

   Identifier "MyMonitor"

   DisplaySize 304 228

  EndSection

  Section "Device"

   ...

   Option "Monitor-FOO" "MyMonitor"

  EndSection

III.4. Forcing outputs off or on

If for some reason one output of your graphic board is enabled while it should not, you might want to disable it (for instance because the number of CRTCs available is limited). To do so, add:

   Option "Ignore" "true"

If for some reason one output is disabled by the driver (for instance VGA-0 on Radeon Xpress 200 because load detection is not reliable in the driver yet), you might want to enable it by force. To do so, add:

   Option "Enable" "true"

Then, you might need to add modes since such an output may not query modes correctly. See "Forcing a preferred mode" to do so.

III.5. Forcing a preferred mode

This is one of rare cases where the ModeLine open is still useful these days. If the preferred mode reported by your monitor isn't the one you want by default, or if there is no preferred mode and the driver does not choose the right one, you might want to force another mode on an output.

Assuming you want to force 1280x1024 at 75Hz at startup, add something like the following to the Monitor section:

   Modeline "1280x1024_75.00" 138.54 1280 1368 1504 1728 1024 1025 1028 1069 -HSync +Vsync

   Option "PreferredMode" "1280x1024_75.00"

The ModeLine line may be obtained by looking at your current Xorg.0.log if the mode is already detected (when it appears in the output of xrandr). Or you may generate a new one using:

  $ gtf 1280 1024 75

  Modeline "1280x1024_75.00" 138.54 1280 1368 1504 1728 1024 1025 1028 1069 -HSync +Vsync

III.6. Example of modern configuration

Here's an example of xorg.conf for a ATI board with DVI-0 (with DisplaySize and preferred mode forced), LVDS (placed on the right of DVI-0) and VGA-0 (disabled) outputs.

Section "InputDevice"

   Identifier "Generic Keyboard"

   Driver "keyboard"

   Option "CoreKeyboard"

   Option "XkbRules" "xorg"

   Option "XkbModel" "pc101"

   Option "XkbLayout" "us"

EndSection

Section "InputDevice"

   Identifier "Configured Mouse"

   Driver "mouse"

   Option "CorePointer"

   Option "Device" "/dev/input/mice"

   Option "Protocol" "ImPS/2"

   Option "Emulate3Buttons" "true"

   Option "ZAxisMapping" "4 5"

EndSection

# external DVI with DisplaySize and preferred mode overriden

Section "Monitor"

   Identifier "External DVI"

   DisplaySize 304 228

   Modeline "1280x1024_60.00" 108.88 1280 1360 1496 1712 1024 1025 1028 1060 -HSync +Vsync

   Option "PreferredMode" "1280x1024_60.00"

EndSection

# internal laptop panel to place on the right of DVI-0

Section "Monitor"

   Identifier "Integrated LCD"

   Option "RightOf" "External DVI"

EndSection

# disable VGA by default

Section "Monitor"

   Identifier "VGA-0"

   Option "Ignore" "true"

EndSection

Section "Device"

   Identifier "ATI Technologies, Inc. M22 [Radeon Mobility M300]"

   Driver "ati"

   BusID "PCI:1:0:0"

   Option "AccelMethod" "EXA"

   Option "Monitor-DVI-0" "External DVI"

   Option "Monitor-LVDS" "Integrated LCD"

   # no need to specific Monitor-VGA-0, it uses the "VGA-0" identifier automatically

EndSection

Section "Screen"

   Identifier "Default Screen"

   Device "ATI Technologies, Inc. M22 [Radeon Mobility M300]"

   DefaultDepth 24

   SubSection "Display"

   Depth 24

   # big virtual screen to place

   Virtual 3072 1200

   EndSubSection

EndSection

Section "ServerLayout"

   Identifier "Default Layout"

   Screen "Default Screen"

   InputDevice "Generic Keyboard"

   InputDevice "Configured Mouse"

EndSection

installer grub

Pour installer grub à partir d'un liveCD avec grub ou bien une linux box.

Copier le dossier genre /boot/grub du liveCD vers le disque de destination

Ensuite lancer grub

#grub

>

Repérer le disque où installer grub

Alors on peut faire au prompt de grub (si les fichiers de boot sont dans /boot/grub)

>find /boot/grub/stage1

et on obtient la liste des hd possibles

(hd0,0)

(hd1,0)

par exemple

Ce que je fais quand il y a plusieurs disques, clefs usb, etc, pour ne pas m'embrouiller, c'est de mettre un fichier genre t.txt dans la racine du disque où installer grub et je fais un

>find /t.txt

et là j'obtiens le disque cible...

ensuite on root le disque et la partition

>root (hdn,m)

puis on installe attention pas de partition indiquée

>setup (hdn)

>quit

Voilà c'est bootable en principe.

Je m'assure toujours que le flag boot est mis sur la partition mais je ne suis pas sûr que ce soit indispensable.

Pour booter sur une partition windows alors que le système est booté sur une carte sd/usb il faut d'abord remapper les drives car windows ne démarre que sur le premier disque.

Donc utiliser genre

title XP

map (hd1) (hd0)

map (hd0) (hd1)

root (hd1,1)

chainloader +1  

Manuel de grub

Toutes les commandes de grub

http://www.gnu.org/software/grub/manual/grub.html#Commands

Extrait :

4.2.6 DOS/Windows

GRUB cannot boot DOS or Windows directly, so you must chain-load them (see Chain-loading). However, their boot loaders have some critical deficiencies, so it may not work to just chain-load them. To overcome the problems, GRUB provides you with two helper functions.

If you have installed DOS (or Windows) on a non-first hard disk, you have to use the disk swapping technique, because that OS cannot boot from any disks but the first one. The workaround used in GRUB is the command map (see map), like this:

   grub> map (hd0) (hd1)

   grub> map (hd1) (hd0)

This performs a virtual swap between your first and second hard drive.

Caution: This is effective only if DOS (or Windows) uses BIOS to access the swapped disks. If that OS uses a special driver for the disks, this probably won't work.

Another problem arises if you installed more than one set of DOS/Windows onto one disk, because they could be confused if there are more than one primary partitions for DOS/Windows. Certainly you should avoid doing this, but there is a solution if you do want to do so. Use the partition hiding/unhiding technique.

If GRUB hides a DOS (or Windows) partition (see hide), DOS (or Windows) will ignore the partition. If GRUB unhides a DOS (or Windows) partition (see unhide), DOS (or Windows) will detect the partition. Thus, if you have installed DOS (or Windows) on the first and the second partition of the first hard disk, and you want to boot the copy on the first partition, do the following:

   grub> unhide (hd0,0)

   grub> hide (hd0,1)

   grub> rootnoverify (hd0,0)

   grub> chainloader +1

   grub> makeactive

   grub> boot

mercredi 21 octobre 2009

samba complitly disabling print

load printers = no

printing = bsd

printcap name = /dev/null

disable spoolss = yes


vendredi 16 octobre 2009

Add & Remove system V init links update-rc.d

update-rc.d - Pour installer ou supprimer les liens vers les scripts d'initialisation de type System-V

Par exemple pour mysql :

update-rc.d mysql defaults 21

update-rc.d mysql-ndb defaults 22

update-rc.d mysql-ndb-mgm defaults 23

Voir aussi install sysv-rc.conf

samedi 10 octobre 2009

Unable to print file to - client-error-bad-request

Surveiller /var/log/cups/error.log

message :

E [] Unsupported character set “iso-8859-1″!

Restart samba

LANG=fr_BE.UTF-8 /etc/init.d/samba restart

mercredi 7 octobre 2009

FIX TIME MACHINE AFTER CHANGING NETWORK INTERFACE

HOT-TO FIX TIME MACHINE MAC OS 10.5.8 AFTER CHANGING NETWORK INTERFACE

Changes to do with the backup drive

cd /Volumes/BACKUP_DRIVE

xattr -l *

pour lister les attributs étendus des fichiers présents.

Sur certains drives Backups.backupdb a un attribut avec la mac address et d'autres non...

Si mac address alors la changer avec la nouvelle

Tout d'abord couper l'acl

fsaclctl -p "/Volumes/BACKUP_DRIVE" -d

écrire la nouvelle adresse

xattr -w com.apple.backupd.BackupMachineAddress 00:1d:60:c1:d9:50 Backups.backupdb

Aller au dir de la machine

cd plutonX

xattr -w com.apple.backupd.BackupMachineAddress 00:1d:60:c1:d9:50 plutonX

réactiver l'acl

fsaclctl -p "/Volumes/BACKUP_DRIVE" -e

changes to do with the network infos

Je n'ai pas pu redémarrer time machine sur ma machine tant que je n'ai pas aussi fait ces changements qui consistent à "reseter" le nom bsd de l'interface à supposer que la précédente carte ethernet était "en0"

J'ai supprimé du dir

/Library/Preferences/SystemConfiguration/

les trois fichiers suivants :

NetworkInterfaces.plist

com.apple.network.identification.plist

preferences.plist

Ensuite reboot et reconfigurer le réseau.

A l'aide de OSXTools86 j'ai aussi réappliqué le fix tile machine (mais je ne pense pas que c'était nécessaire).

mardi 22 septembre 2009

microsoft excel (mac) - print as pdf - page setup dialog

Pour imprimer en un seul fichier PDF la totalité du workbook il faut bien prendre garde que dans le Page setup de chaque feuille le First Page number est à auto, car si l'on spécifie un numéro de page qui n'est pas dans la continuité des pages précédentes, la feuille est imprimée dans un fichier PDF à part.


200909221533.jpg

lundi 21 septembre 2009

UBUNTU : Changement de l'éditeur de texte par défaut

sudo update-alternatives --config editor


mardi 15 septembre 2009

applescript open ssh window in terminal with specific encoding settings

Je ne suis pas certain du tout que ce script soit tout à fait comme il faut... mais comme je n'ai pas grande idée de comment exactement fonctionne applescript j'ai bidouillé ces deux scripts en glanant ça et là des idées... sans doute y a-t-il une manière plus élégante d'écrire ça... sans doute même des fonctions et des propriétés que j'ignore, mais pour simplement ouvrir 3 fenêtres de terminal avec ssh... du moment que ça marche, c'est bon pour moi.


property commandString : "ssh user@host" -- < Edit this line as desired.


tell application "Terminal" -- Get a free window to run the commandString,

set windowCount to (count of the windows)

--activate

if ((count of windows) is 1) then

close window 1 -- attention, s'il n'y a qu'une seule fenêtre ouverte, elle sera fermée

--tell window 1

-- set miniaturized to true

--end tell

repeat with w from 1 to 3 -- je veux 3 connexions

tell window (windowCount + 1)

do script commandString

end tell

tell application "Terminal" to set current settings of first window to settings set 7

  

--settings 7 = my colors and ISO-8859-1ISO Latin-1 encoding and police 16 pt

tell front window

set zoomed to true

-- Je veux que mes 3 fenêtres soient maximizées et occupent tout l'écran

end tell

end repeat

else

repeat with w from 1 to 3

tell window (windowCount + 1)

do script commandString

end tell

tell application "Terminal" to set current settings of first window to settings set 7

tell front window

set zoomed to true

end tell

end repeat

end if

end tell


*** Autre version, avec trois fenêtres disposées 1 full screen et 2 half screen ***

pour un écran de 1680 x 1050


property commandString : "ssh meteo@mars" -- < Edit this line as desired.


tell application "Terminal" -- Get a free window to run the commandString,

set windowCount to (count of the windows)

activate

if ((count of windows) is 1) then

close window 1

--tell window 1

-- set miniaturized to true

--end tell

repeat with w from 1 to 3

tell window (windowCount + 1)

do script commandString

end tell

tell application "Terminal" to set current settings of first window to settings set 7

tell front window

if w is 1 then

set zoomed to true

else

if w is 2 then

set position to {20, 22}

set size to {825, 960}

--properties

--tell application "Terminal" to set bounds of first window to {0, 0, 820, 975}

else

set position to {850, 22}

set size to {825, 960}

--properties

--tell application "Terminal" to set bounds of first window to {0, 670, 820, 975}

end if

end if

end tell

end repeat

else

repeat with w from 1 to 3

tell window (windowCount + 1)

do script commandString

end tell

tell application "Terminal" to set current settings of first window to settings set 7

tell front window

if w is 1 then

set zoomed to true

else

if w is 2 then

set position to {20, 22}

set size to {825, 960}

--properties

--tell application "Terminal" to set bounds of first window to {0, 0, 820, 975}

else

set position to {850, 22}

set size to {825, 960}

--properties

--tell application "Terminal" to set bounds of first window to {0, 670, 820, 975}

end if

end if

end tell

end repeat

end if

end tell


lundi 14 septembre 2009

how to know what is the active database in mysql

select database();

VIM turn off matchparen plugin / stop highlighting matching brackets

to disable the plugin

completely, you can use the command

let loaded_matchparen = 1

in your ~/.vimrc

To turn it off

:NoMatchParen

To turn it back on

:DoMatchParen

vendredi 11 septembre 2009

GRANT ALL PRIVILEGES : MYSQL

Pour donner accès aux dB à un utilisateur :

Se logger comme root dans mysql

mysql -u root mysql -p

au prompt : password

puis

GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY '' WITH GRANT OPTION;

flush privileges;

Pour vérifier :

SELECT user, host, password FROM user;

à la place de localhost = connection uniquement en local, on peut mettre % pour pouvoir se logger à distance.

jeudi 10 septembre 2009

mysql backup

Les fichiers des db se trouvent (ubuntu 8.04)

/var/lib/mysql/

On peut simplement faire une copie des fichiers mais il faut mettre un lock write avant.

C'est ce que fait le script mysqlhotcopy

Syntaxe :

A exécuter comme root

mysqlhotcopy metar_2009 -u meteo -p '' --addtodest /tmp/mysqlbackup

mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory

--addtodest

Do not rename target directory (if it exists); merely add files to it.

--dryrun, -n

Report actions without performing them.

--method=command

The method for copying files (cp or scp).

--password=password, -ppassword

The password to use when connecting to the server. Note that the password value is not optional for this option, unlike for other MySQL programs. You can use an option file to avoid giving the password on the command line.

--user=user_name, -u user_name

The MySQL user name to use when connecting to the server.

6.1. Database Backups

This section summarizes some general methods for making backups.

Making Backups by Copying Files

MyISAM tables are stored as files, so it is easy to do a backup by copying files. To get a consistent backup, do aLOCK TABLES on the relevant tables, followed by FLUSH TABLES for the tables. See Section 12.4.5, “LOCK TABLES and UNLOCK TABLES Syntax”, and Section 12.5.6.3, “FLUSH Syntax”. You need only a read lock; this allows other clients to continue to query the tables while you are making a copy of the files in the database directory. The FLUSH TABLES statement is needed to ensure that the all active index pages are written to disk before you start the backup.

Making Delimited-Text File Backups

To create a text file containing a table's data, you can use SELECT * INTO OUTFILE 'file_name' FROMtbl_name. The file is created on the MySQL server host, not the client host. For this statement, the output file cannot already exist because allowing files to be overwritten would constitute a security risk. See Section 12.2.8, “SELECT Syntax”. This method works for any kind of data file, but saves only table data, not the table structure.

To reload the output file, use LOAD DATA INFILE or mysqlimport.

Making Backups with mysqldump or mysqlhotcopy

Another technique for backing up a database is to use the mysqldump program or the mysqlhotcopy script.mysqldump is more general because it can back up all kinds of tables. mysqlhotcopy works only with some storage engines. (See Section 4.5.4, “mysqldump — A Database Backup Program”, and Section 4.6.9, “mysqlhotcopy — A Database Backup Program”.)

Create a full backup of your database:

shell> mysqldump --tab=/path/to/some/dir --opt db_name

Or:

shell> mysqlhotcopy db_name /path/to/some/dir

You can also create a binary backup simply by copying all table files (*.frm, *.MYD, and *.MYI files), as long as the server isn't updating anything. The mysqlhotcopy script uses this method. (But note that these methods do not work if your database contains InnoDB tables. InnoDB does not necessarily store table contents in database directories, and mysqlhotcopy works only for MyISAM and ISAM tables.)

For InnoDB tables, it is possible to perform an online backup that takes no locks on tables; see Section 4.5.4, “mysqldump — A Database Backup Program”.

smbpasswd and pdbedit samba

pdbedit remplace smbpasswd pour éditer le fichier smbpasswd.

mercredi 9 septembre 2009

MYSQL FROM_UNIXTIME, DATE_FORMAT, SQLITE3,

Avec sqlite3 j'utilise strftime('%w',unixtime,'unixepoch','localtime') pour obtenir le jour de la semaine sous forme numérique de 0 à 6

strftime('%w',unixtime,'unixepoch','localtime')

Avec mysql la commande équivalente est :

FROM_UNIXTIME(unixtime,'%w')

Pas besoin de préciser localtime, car la conversion se fait directement selon le timezone (par défaut SYSTEM)

FROM_UNIXTIME(unix_timestamp), FROM_UNIXTIME(unix_timestamp,format)

Returns a representation of the unix_timestamp argument as a value in 'YYYY-MM-DD HH:MM:SS' orYYYYMMDDHHMMSS.uuuuuu format, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone. unix_timestamp is an internal timestamp value such as is produced by the UNIX_TIMESTAMP() function.

If format is given, the result is formatted according to the format string, which is used the same way as listed in the entry for the DATE_FORMAT() function.

mysql> SELECT FROM_UNIXTIME(1196440219);
-> '2007-11-30 10:30:19'
mysql> SELECT FROM_UNIXTIME(1196440219) + 0;
-> 20071130103019.000000
mysql> SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(),
->                      '%Y %D %M %h:%i:%s %x');
-> '2007 30th November 10:30:59 2007'

Note: If you use UNIX_TIMESTAMP() and FROM_UNIXTIME() to convert between TIMESTAMP values and Unix timestamp values, the conversion is lossy because the mapping is not one-to-one in both directions. For details, see the description of the UNIX_TIMESTAMP() function.

  • DATE_FORMAT(date,format)

    Formats the date value according to the format string.

    The following specifiers may be used in the format string. The “%” character is required before format specifier characters.

    Specifier Description
    %a Abbreviated weekday name (Sun..Sat)
    %b Abbreviated month name (Jan..Dec)
    %c Month, numeric (0..12)
    %D Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)
    %d Day of the month, numeric (00..31)
    %e Day of the month, numeric (0..31)
    %f Microseconds (000000..999999)
    %H Hour (00..23)
    %h Hour (01..12)
    %I Hour (01..12)
    %i Minutes, numeric (00..59)
    %j Day of year (001..366)
    %k Hour (0..23)
    %l Hour (1..12)
    %M Month name (January..December)
    %m Month, numeric (00..12)
    %p AM or PM
    %r Time, 12-hour (hh:mm:ss followed by AM or PM)
    %S Seconds (00..59)
    %s Seconds (00..59)
    %T Time, 24-hour (hh:mm:ss)
    %U Week (00..53), where Sunday is the first day of the week
    %u Week (00..53), where Monday is the first day of the week
    %V Week (01..53), where Sunday is the first day of the week; used with %X
    %v Week (01..53), where Monday is the first day of the week; used with %x
    %W Weekday name (Sunday..Saturday)
    %w Day of the week (0=Sunday..6=Saturday)
    %X Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V
    %x Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v
    %Y Year, numeric, four digits
    %y Year, numeric (two digits)
    %% A literal “%” character
    %x x, for any “x” not listed above

    Ranges for the month and day specifiers begin with zero due to the fact that MySQL allows the storing of incomplete dates such as '2014-00-00'.

    The language used for day and month names and abbreviations is controlled by the value of the lc_time_namessystem variable (Section 9.8, “MySQL Server Locale Support”).

    DATE_FORMAT() returns a string with a character set and collation given by character_set_connection andcollation_connection so that it can return month and weekday names containing non-ASCII characters.

    mysql> SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
    -> 'Sunday October 2009'
    mysql> SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
    -> '22:23:00'
    mysql> SELECT DATE_FORMAT('1900-10-04 22:23:00',
    ->                 '%D %y %a %d %m %b %j');
    -> '4th 00 Thu 04 10 Oct 277'
    mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00',
    ->                 '%H %k %I %r %T %S %w');
    -> '22 22 10 10:23:00 PM 22:23:00 00 6'
    mysql> SELECT DATE_FORMAT('1999-01-01', '%X %V');
    -> '1998 52'
    mysql> SELECT DATE_FORMAT('2006-06-00', '%d');
    -> '00'