[fedora] pb mysql

Résolu
Salut !

Je voudrais me connecter à mon serveur mysql en ligne de commande :

[root@localhost /] # mysql -u root


mais il y a une erreur :

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 


Je pense qu'il doit y avoir une erreur de droit car qd j'ouvre le fichier mysql.sock il est vide avec marqué [permission denied]

De plus je voudrais qu'il essaie de se connecter avec le fichier "/opt/lampp/var/mysql/mysql.sock" et non avec le fichier "/var/lib/mysql/mysql.sock" !

Quelqu'un peut-il m'aider ?
Merci
Configuration: Linux Fedora
Firefox 2.0.0.3

13 réponses

Résumé de la discussion

La difficulté réside dans une impossibilité de se connecter localement à MySQL via le socket, entraînant l'erreur Can't connect to local MySQL server through socket et des conflits entre installations Fedora et XAMPP. Des pistes suggèrent d'utiliser le socket de lampp (/opt/lampp/var/mysql/mysql.sock), de lancer le daemon mysqld, et de préférer le client /opt/lampp/bin/mysql pour éviter les conflits avec /usr/bin/mysql. D'autres réponses évoquent des permissions, SELinux et la nécessité de démarrer le service mysqld ou d'ajuster le fichier my.cnf pour pointer vers le socket utilisé. En pratique, plusieurs utilisateurs recommandent d'examiner les fichiers my.cnf dans /etc et /opt/lampp/etc, puis de remplacer le chemin socket par /opt/lampp/var/mysql/mysql.sock et de relancer le service.

Bobot (l’IA à votre service)
  1. Modérateur
    je crois que le problème est là

    mysql: /usr/bin/mysql /usr/lib/mysql /usr/include/mysql /usr/share/mysql /opt/lampp/bin/mysql.server /opt/lampp/bin/mysql /usr/share/man/man1/mysql.1.gz

    tu as un conflit

    quant tu tapes
    mysql --......c'est /usr/bin/mysql qui s'exécute donc c'est /etc/my.cnf qui est lu

    tu dois taper plûtot
    /opt/lampp/bin/mysql .....
    pour utiliser ton mysql de lamp

    En bref il fallait d'abord désinstaller le mysql de fedora avant d'installer lamp, puisque maintenant c'est un petit bordel chez toi :-))

    1. bonjour tt le monde je suis debutant en linux et la jai fait un script pour aceder a ma base de donnée le script marche sous windows mais ne sexecute pas sous linux et je demande de l'aide voici le script
      <?php
      $base = mysql_connect (192.168.1.230, 'root', 'mot de passe du root');
      mysql_select_db ('bea', $base) or die ("erreur de connexion base");
      ?>
      1. Modérateur
        Salut,

        De rien :-))

        Petite précision
        dans ce message fedora pb mysql#25

        J'ai tapé ta commande :

        /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --user=nobody --pid-file=/opt/lampp/var/mysql/localhost.localdomain.pid --skip-external-locking --port=3306 --socket=/opt/lampp/var/mysql/mysql.sock


        en fait ce n'était pas une commande mais un copier/coller d'un résultat des commandes que je t'ai demandé
        mais c'est vrai que je ne l'ai pas precisé. désolé

        1. En tout cas ça marche et c'est nickel !!!!!!!
          Sa fait 3 semaines que je suis sur l'install Nagios-Oreon et on dirait que je vais bientot en voir le bout !
          Je l'aurais !
      2. C'est bon je suis rentré dans mysql !!!

        [root@localhost ~]# /opt/lampp/bin/mysql -u root
        Welcome to the MySQL monitor.  Commands end with ; or \g.
        Your MySQL connection id is 10
        Server version: 5.0.41 Source distribution
        Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
        mysql> 
        


        Mais j'ai un tout petit probleme encore ...

        Je veux utilisé la commande suivante :
        GRANT ALL PRIVILEGES ON nagios.* TO 'nagios@localhost identified by 'P@SSWORD';

        puis quitter mysql.

        seulement une fois la commande tapée je ne retourne pas comme prévu sur le prompt
        mysql> 

        mais je tombe sur le prompt
            '>   
        !
        Que dois-je faire dans ce prompt et comment le quitter, lui et mysql ?
        1. Euh en fait c'est bon, pour le probleme sur le prompt car quand j'ai tapé la commande :
          GRANT ALL PRIVILEGES ON nagios.* TO 'nagios@localhost identified by 'P@SSWORD';

          J'avais oublié une cote :
           'nagios'@localhost 


          meci beaucoup de votre patience à tous pour m'aider à resoudre ce probleme et plus particulièrement à lami20j pour son aide très précieuse !
      3. Bonjour tout le monde,

        Je vois qu'on s'approche de la solution .......

        :-))
        1. Modérateur
          0:00 /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --user=nobody --pid-file=/opt/lampp/var/mysql/localhost.localdomain.pid --skip-external-locking --port=3306 --socket=/opt/lampp/var/mysql/mysql.sock


          D'ailleurs on vois ben que le daemon fonctionne essaie cette commande et affiche le résultat
          /opt/lampp/bin/mysql -u root -p
          --
          lami20j
          1. J'ai tapé ta commande :

            /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --user=nobody --pid-file=/opt/lampp/var/mysql/localhost.localdomain.pid --skip-external-locking --port=3306 --socket=/opt/lampp/var/mysql/mysql.sock


            resultat :
            
            070615  9:38:10 [ERROR] Can't start server: Bind on TCP/IP port: Address already in use
            070615  9:38:10 [ERROR] Do you already have another mysqld server running on port: 3306 ?
            070615  9:38:10 [ERROR] Aborting
            
            070615  9:38:10 [Note] /opt/lampp/sbin/mysqld: Shutdown complete


            Je dirais que ya un petit probleme !!! :-)

            Pour la seconde la commande marche sans le
            -p


            Merci ça marche !
            Le probleme est résolu !
            Mais pourrais tu m'expliquer pourquoi ça marche maintenant alors que avant non ?
            Parceque j'avais déjà tapé cette commande avant et ça ne marchait pas !
            Quelle est la commande qui a modifiée ma config de my sql ?
        2. Salut,

          beaucoup de posts sur les forums à propos de ce message d'erreur ....et notamment sur fedora !

          autres pistes :
          - lancer le service mysqld : ./mysqld start
          - problème de permissions
          - lancer la commande mysql avec l'option --socket=/tmp/mysql.sock (devrait marcher en root).
          etc .....

          une piste ici (si c'est le cas pour toi) :
          I have a solution to this problem. The root cause seems to be within SELinux.
          I am using Fedora Core 6 with SELinux, so this should work for all systems with SELinux installed and active.
          Root access is required
          Select: System - Administration - Security Level and Firewall
          Select the SELinux tab and expand Modify SELinux policy, scroll down to SELinux service protection, expand it and check the box for 'Disable SELiunx protection for mysqld daemon'.
          After that select: System - Administration - Server Settings - Services and scroll down to background service mysql and click start. The mysql service will start.
          or
          Log in as root or su in terminal as root and use: /etc/init.d/mysql start.


          :-))
          1. Modérateur
            Salut,

            and check the box for 'Disable SELiunx protection for mysqld daemon'.

            avec la précisions que ce n'est pas vraiment une solution si on contourne le problème
            normalement il doit fonctionner avec SELinux
          2. @lami20jSalut,

            avec la précisions que ce n'est pas vraiment une solution si on contourne le problème
            normalement il doit fonctionner avec SELinux


            tout à fait d'accord avec toi ! :-)
            je l'entendais aussi comme ça : comme une rustine en attendant de trouver la solution finale !
            D'ailleurs pour un : sa solution a été une réinstallation complète du système et depuis mysql fonctionne normalement !

            :-))
          3. Salut, le résultat des commandes que tu m'a données :

            autres pistes :
            - lancer le service mysqld : ./mysqld start
            - problème de permissions
            - lancer la commande mysql avec l'option --socket=/tmp/mysql.sock (devrait marcher en root).
            etc ..... 


            [root@localhost ~]# ./mysqld start 
            bash: ./mysqld: Aucun fichier ou répertoire de ce type
            [root@localhost ~]# mysql -- socket=/tmp/mysqL.sock
            ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
            


            !!!
          4. Sinon pour la partie en graphique :

            une piste ici (si c'est le cas pour toi) :
            I have a solution to this problem. The root cause seems to be within SELinux.
            I am using Fedora Core 6 with SELinux, so this should work for all systems with SELinux installed and active.
            Root access is required
            Select: System - Administration - Security Level and Firewall
            Select the SELinux tab and expand Modify SELinux policy, scroll down to SELinux service protection, expand it and check the box for 'Disable SELiunx protection for mysqld daemon'.
            After that select: System - Administration - Server Settings - Services and scroll down to background service mysql and click start. The mysql service will start.
            or
            Log in as root or su in terminal as root and use: /etc/init.d/mysql start.
            


            C'est différent sous fedora 7, j'ai selectionné 'Firewall & SeLinux' , onglet SELinux, et là une seule option :
            parametres SELinux (Strict, Permissif, Désactivé) !

            2nde partie: 'Services' , onglet services d'arriere plan, mysqld n'est pas dans la liste des services !!!
        3. Modérateur
          Non, ce n'est pas grave :-)
          Tu dois avoir un conflit entre 2 installations de mysql

          affiche
          ps aux | grep mysql
          whereis mysql{,d}

          Je ne comprends pas où tu veut en venir !
          Moi, oui :-))
          Je veux savoir sous quel utilisateur le daemon mysqld est demarré
          Enfin affiche ce que je te demande et je vais voir ce que je peux faire
          Ensuite je vais t'expliquer (bien sûr si j'arrive à te depanner :-))
          1. Bonjour !

            voilà le resultat des commandes
            ps aux | grep mysql

            whereis mysql{,d}


            [root@localhost ~]# ps aux | grep mysql
            root      1994  0.0  0.1   4036   760 pts/1    S+   08:08   0:00 grep mysql
            root     29746  0.0  0.2   4636  1168 ?        S    Jun14   0:00 /bin/sh /opt/lampp/bin/mysqld_safe --datadir=/opt/lampp/var/mysql --pid-file=/opt/lampp/var/mysql/localhost.localdomain.pid
            nobody   29779  0.0  0.7  26500  3880 ?        Sl   Jun14   0:00 /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --user=nobody --pid-file=/opt/lampp/var/mysql/localhost.localdomain.pid --skip-external-locking --port=3306 --socket=/opt/lampp/var/mysql/mysql.sock
            [root@localhost ~]# whereis mysql{,d}
            mysql: /usr/bin/mysql /usr/lib/mysql /usr/include/mysql /usr/share/mysql /opt/lampp/bin/mysql.server /opt/lampp/bin/mysql /usr/share/man/man1/mysql.1.gz
            mysqld:
            [root@localhost ~]# 


            Je ne voit pas trop ce que cela siginfie mais voila ! :-)
        4. Modérateur
          affiche
          grep mysql /etc/passwd
          --
          lami20j
          1. j'ai tapé ta commande mais je ne voit pas de résultat !
            Que doit faire cette commande ?
          2. @max-lbJe ne comprends pas où tu veut en venir !

            merci de ta patience car je boss depuis peu sous linux et j'ai encore pas mal de diffficulté ! :-)
          3. @max-lbJe viens de m'apercevoir que j'avais un second fichier my.cnf .
            Il est dans le répertoire /opt/lampp/etc/
            mais il est différent de l'autre ! Je ne sais pas si c'est normal qu'il y est un autre, en plus il est différent :

            # Example MySQL config file for medium systems.
            #
            # This is for a system with little memory (32M - 64M) where MySQL plays
            # an important part, or systems up to 128M where MySQL is used together with
            # other programs (such as a web server)
            #
            # You can copy this file to
            # /etc/my.cnf to set global options,
            # mysql-data-dir/my.cnf to set server-specific options (in this
            # installation this directory is /opt/lampp/var/mysql) or
            # ~/.my.cnf to set user-specific options.
            #
            # In this file, you can use all long options that a program supports.
            # If you want to know which options a program supports, run the program
            # with the "--help" option.
            
            # The following options will be passed to all MySQL clients
            [client]
            #password       = your_password
            port            = 3306
            socket          = /opt/lampp/var/mysql/mysql.sock
            
            # Here follows entries for some specific programs
            # The MySQL server
            [mysqld]
            port            = 3306
            socket          = /opt/lampp/var/mysql/mysql.sock
            skip-locking
            key_buffer = 16M
            max_allowed_packet = 1M
            table_cache = 64
            sort_buffer_size = 512K
            net_buffer_length = 8K
            read_buffer_size = 256K
            read_rnd_buffer_size = 512K
            myisam_sort_buffer_size = 8M
            
            # Don't listen on a TCP/IP port at all. This can be a security enhancement,
            # if all processes that need to connect to mysqld run on the same host.
            # All interaction with mysqld must be made via Unix sockets or named pipes.
            # Note that using this option without enabling named pipes on Windows
            # (via the "enable-named-pipe" option) will render mysqld useless!
            #
            #skip-networking
            # Replication Master Server (default)
            # binary logging is required for replication
            # log-bin deactivated by default since XAMPP 1.4.11
            #log-bin=mysql-bin
            
            # required unique id between 1 and 2^32 - 1
            # defaults to 1 if master-host is not set
            # but will not function as a master if omitted
            server-id       = 1
            
            # Replication Slave (comment out master section to use this)
            #
            # To configure this host as a replication slave, you can choose between
            # two methods :
            #
            # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
            #    the syntax is:
            #
            #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
            #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
            #
            #    where you replace <host>, <user>, <password> by quoted strings and
            #    <port> by the master's port number (3306 by default).
            #
            #    Example:
            #
            #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
            #    MASTER_USER='joe', MASTER_PASSWORD='secret';
            #
            # OR
            #
            # 2) Set the variables below. However, in case you choose this method, then
            #    start replication for the first time (even unsuccessfully, for example
            #    if you mistyped the password in master-password and the slave fails to
            #    connect), the slave will create a master.info file, and any later
            #    change in this file to the variables' values below will be ignored and
            #    overridden by the content of the master.info file, unless you shutdown
            #    the slave server, delete master.info and restart the slaver server.
            #    For that reason, you may want to leave the lines below untouched
            #    (commented) and instead use CHANGE MASTER TO (see above)
            # required unique id between 2 and 2^32 - 1
            # (and different from the master)
            # defaults to 2 if master-host is set
            # but will not function as a slave if omitted
            #server-id       = 2
            #
            # The replication master for this slave - required
            #master-host     =   <hostname>
            #
            # The username the slave will use for authentication when connecting
            # to the master - required
            #master-user     =   <username>
            #
            # The password the slave will authenticate with when connecting to
            # the master - required
            #master-password =   <password>
            #
            # The port the master is listening on.
            # optional - defaults to 3306
            #master-port     =  <port>
            #
            # binary logging - not required for slaves, but recommended
            #log-bin=mysql-bin
            # Point the following paths to different dedicated disks
            #tmpdir         = /tmp/
            #log-update     = /path-to-dedicated-directory/hostname
            
            # Uncomment the following if you are using BDB tables
            #bdb_cache_size = 4M
            #bdb_max_lock = 10000
            
            # Comment the following if you are using InnoDB tables
            skip-innodb
            innodb_data_home_dir = /opt/lampp/var/mysql/
            innodb_data_file_path = ibdata1:10M:autoextend
            innodb_log_group_home_dir = /opt/lampp/var/mysql/
            innodb_log_arch_dir = /opt/lampp/var/mysql/
            # You can set .._buffer_pool_size up to 50 - 80 %
            # of RAM but beware of setting memory usage too high
            innodb_buffer_pool_size = 16M
            innodb_additional_mem_pool_size = 2M
            # Set .._log_file_size to 25 % of buffer pool size
            innodb_log_file_size = 5M
            innodb_log_buffer_size = 8M
            innodb_flush_log_at_trx_commit = 1
            innodb_lock_wait_timeout = 50
            [mysqldump]
            quick
            max_allowed_packet = 16M
            
            [mysql]
            no-auto-rehash
            # Remove the next comment character if you are not familiar with SQL
            #safe-updates
            
            [isamchk]
            key_buffer = 20M
            sort_buffer_size = 20M
            read_buffer = 2M
            write_buffer = 2M
            
            [myisamchk]
            key_buffer = 20M
            sort_buffer_size = 20M
            read_buffer = 2M
            write_buffer = 2M
            
            [mysqlhotcopy]
            interactive-timeout
            


            Voilà ce que donne ce second my.conf !
            C'est grave docteur ? :-)
        5. Modérateur
          mets un # avant cette ligne
          socket=/var/lib/mysql/mysql.sock

          et écrit celle ci
          socket=/opt/lampp/var/mysql/mysql.sock


          donc tu dois avoir comme ça

          #socket=/var/lib/mysql/mysql.sock
          socket=/opt/lampp/var/mysql/mysql.sock


          1. J'ai commenter la ligne et créee l'autre.
            Mais toujours la meme erreur :
            ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 


            Il continue à chercher dans /var/lib/mysql/mysql.sock
            en mettant la commande suivante :
            /opt/lampp/var/mysql/mysql.sock -u root 

            Je luis specifie le chemin donc il cherche bien dans /opt/lampp/var/mysql/ ,
            mais il me refuse l'entrée :
            bash: /opt/lampp/var/mysql/mysql.sock: Permission non accordée

            tout comme quand je me place dans le repertoire :

            /opt/lampp/var/mysql/
            vi mysql.sock 


            entreé dans le fichier :
            --------------------------------------------------
            ~
            ~
            ~
            "mysql.sock" [Permission Denied]
            --------------------------------------------------

            fichier vierge !
        6. Modérateur
          Cherche le fichier my.cnf
          Il est normalement dans /etc/
          tu l'ouvres avec un editeur de text et tu fais un copier/coller ici
          1. Ok je l'ai trouvé il était bien dans /etc

            mais j'ai pas très bien compris ce que tu veut que je fasse avec !
            je l'ai ouvert avec vi :

            [mysqld]
            datadir=/var/lib/mysql
            socket=/var/lib/mysql/mysql.sock
            user=mysql
            # Default to using old password format for compatibility with mysql 3.x
            # clients (those using the mysqlclient10 compatibility package).
            old_passwords=1
            
            [mysqld_safe]
            log-error=/var/log/mysqld.log
            pid-file=/var/run/mysqld/mysqld.pid
            
        7. Modérateur
          Salut,

          Puisqu'il cherchel le fichier ici
          '/var/lib/mysql/mysql.sock'


          et pas dans /opt

          Affiche ton fichier de configuration
          1. je vieux bien mais le fichier de config est où et qu'est-ce qu'il faut que j'en fasse ! :)
          2. Deplus quand je regarde dans /var/lib/ il n'y a aucun repertoire 'mysql' il ne le trouvera donc jamais !
        8. j'ai essayé la commande suivante :

          /opt/lampp/var/mysql/mysql.sock -u root


          Il apparait bien que c'est un probleme de droit :

          bash: /opt/lampp/var/mysql/mysql.sock: Permission non accordée


          Je n'arrive pas à accéder au fichier mysql.sock meme après un
          chmod 777 mysql.sock

          Comment faire pour le régler ?

          Merci de m'aider