Différences entre les versions de « Mysql commandes diverses »

De BlaxWiki
Aller à la navigationAller à la recherche
Ligne 58 : Ligne 58 :
== Reset du password root==
== Reset du password root==
<pre>
<pre>
1. Take down the mysqld server by sending a kill (not kill -9) to the mysqld server. The pid is stored in a `.pid' file, which is normally in the MySQL database directory:
1. Arreter le serveur mysql (avec le script d'init)


shell> kill `cat /mysql-data-directory/hostname.pid`
2. Sous le user mysql :
# mysqld --skip-grant-tables --skip-networking --datadir=/data/mysql/data --pid-file=/data/mysql/data/antispam.amesys.fr.pid --socket=/data/mysql/data/mysql.sock
(les options --datadir, --pid-file et --socket sont optionnellesà


You must be either the Unix root user or the same user mysqld runs as to do this.
3. Sous le user root  
2. Restart mysqld with the --skip-grant-tables option.
# mysql --socket=/data/mysql/data/mysql.sock
3. Set a new password with the mysqladmin password command:


shell> mysqladmin -u root password 'mynewpassword'
mysql> use mysql;


4. Now you can either stop mysqld and restart it normally, or just load the privilege tables with:
mysql> UPDATE user SET password=PASSWORD('Ch00bAk1') WHERE user="root";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0


shell> mysqladmin -h hostname flush-privileges
mysql> flush privileges;
 
Query OK, 0 rows affected (0.00 sec)
5. After this, you should be able to connect using the new password.
 
Alternatively, you can set the new password using the mysql client:
 
1. Take down and restart mysqld with the --skip-grant-tables option as described above.
2. Connect to the mysqld server with:
 
shell> mysql -u root mysql
 
3. Issue the following commands in the mysql client:
 
mysql> UPDATE user SET Password=PASSWORD('mynewpassword')
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
 
4. After this, you should be able to connect using the new password.
5. You can now stop mysqld and restart it normally.
</pre>
</pre>
[[Catégorie:Software]]
[[Catégorie:Software]]

Version du 11 juin 2012 à 14:14

Commandes divers

 - describe nomdunetable : info sur la structure d'une table
 - show full processlist : info sur les requetes en cours
 - show variables : donne les variables du serveur mysql
 - show variables like '%char%': donne les variables incluant *char*
 - \G à la fin d'une requete sort le résultat en ligne et non en colonne
 - \P more : définit le pager sur more, ce qui permet d'afficher page par page
 - show grants for user@host : info sur les droits de ce user
 - select (count(*)) from user : retourne le nombre 
 - insert into whitelist set login="smtp@corp.lecroupier.com", passwd="oueteo";
 - select if( find_in_set('Migrated',migrated),'','') from easy.mbox ; 
 - GRANT ALL PRIVILEGES ON *.* TO 'root'@'IP' IDENTIFIED BY 'MDP"; (rajoute un user root pour taper depuis une autre ip que localhost)
 - UPDATE mysql.user SET Password = PASSWORD('NEWPASSWD') where User="vision"; (modifie le password)

Exemple de création de tables:
CREATE TABLE `pop3_imap_proxy` (`user` varchar(128) NOT NULL,`servername` varchar(255) NOT NULL,`port` varchar(8) default NULL,PRIMARY KEY  (`user`),
KEY `idxtblPerdition_user` (`user`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Pb avec mysql 4.1 et client 3.23

mysql > SET PASSWORD FOR 'postfix'@'localhost' = OLD_PASSWORD('reixaetu');
mysql > flush privileges;

ou

# mysqladmin -uroot! -p -hip_du_serveur! old-password nouveaupassword!

ou

dans le my.cnf en mettant :
set_variable = old_passwords=1 dans la partie [mysqld]

Suppression / modification d'un enregistremen

suppression : DELETE FROM nom_table WHERE id=1 and name="lkl"

modification : UPDATE nom_table SET prenom='Jean-Pierre', nom='Papin', ville='Marseille', enfants=3 WHERE id=1
Si on est sur qu'il n'y a qu un enregistrement à supprimer, on peut rajouter limit 1 à la fin dans le cas où nous ne sommes pas sur
<pre>

== Création d'un user ==

Création du user root pour une connexion depuis une autre ip, et affectation de tous les droits
<pre>
CREATE USER 'root'@'172.26.15.17' IDENTIFIED BY 'tVBBF1OO';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.26.15.17' WITH GRANT OPTION;

Commandes mysql en bash

mysql -u postfix -e "INSERT into mailbox (username,password,name,maildir,domain) values ('$MBOX', '$PASSWD', '$NAME', '$MBOX/', '$DOMAIN');" -pmotdepasse postfix

Reset du password root

1. Arreter le serveur mysql (avec le script d'init)

2. Sous le user mysql :
# mysqld --skip-grant-tables --skip-networking --datadir=/data/mysql/data --pid-file=/data/mysql/data/antispam.amesys.fr.pid --socket=/data/mysql/data/mysql.sock
(les options --datadir, --pid-file et --socket sont optionnellesà

3. Sous le user root 
# mysql --socket=/data/mysql/data/mysql.sock

mysql> use mysql;

mysql> UPDATE user SET password=PASSWORD('Ch00bAk1') WHERE user="root";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)