rendered paste bodyDicas MySQL
===== =====
MySQL Administrator.
-> Instalação do bin: gunzip -c mysql-administrator-x.x.x-alpha-linux.tar.gz | tar xv -C /opt
MySQL Control Center.
-> Instalação do bin: tar zxfv arquivo.tar.gz;
* configuração:
-> (root)# cp /etc/my-medium.cnf /etc/my.cnf
|> (root)# su - mysql -c "mysql_install_db"
* 1-iniciação (ver serviço) e 2-segurança
1-> (root)# mysqld_safe --user=mysql &
2-> (root)# mysql_secure_installation
* cliente
|> # mysql -h host -u root -p
* Queries administração: 1-adiciona, 2-remove usuários; 3-seta o password
1-> mysql> GRANT {all|} ON {nivel} TO username@host identified by 'password';
2-> mysql> delete from user where user="username";
3-> (root)# mysqladmin -u root -h host password 'password' -p
|> mysql> SET PASSWORD FOR 'username'@'localhost' = PASSWORD('newPassword');
* text-mode cliente:
-> $ mysql -u user -h host -p
-> $ mysql
* 1-exibe, 2-cria, 3-manipula e 4-deleta databases:
1-> show databases;
--> select DATABASE();
2-> create database databasename;
3-> use databasename # sem ponto-virgula
4-> drop database [if exists] databasename
* 1-exibe e 2-cria tabelas; 3-insere, 4-exibe, 5-atualiza e 6-deleta dados:
1-> show tables;
--> describe tablename;
2-> create tables tablename (fieldname1 type, fieldname2 type, ...);
---> descreve tablename com campos dos tipos:
--|> -> char(M) M bytes, 1 <= M <= 255;
--|> -> varchar(M) L+1 bytes, onde L <= M e 1 <= M <= 255;
--|> -> tinyblob, tinytext L+1 bytes, onde L < 2^8;
--|> -> blob, text L+2 bytes, onde L < 2^16;
--|> -> mediumblob, mediumtext L+3 bytes, onde L < 2^24;
--|> -> longblob, longtext L+4 bytes, onde L < 2^32;
--|> -> enum('valor1',...) 1 or 2 bytes, depende do numero de valores (max 65535 valores);
--|> -> set('valor1',...) 1, 2, 3, 4 or 8 bytes, depende do numero de membros (max 64 membros);
--|> -> tinyint 1 byte (-128 a 127)
--|> -> smalint 2 bytes (-32768 a 32767)
--|> -> mediumint 3 bytes (-8388608 a 8388607)
--|> -> int 4 bytes (-2147483648 a 2147483647)
--|> -> integer 4 bytes
--|> -> bigint 8 bytes (-9223372036854775808 a 9223372036854775807)
--|> -> float(X) 4 if X <= 24 or 8 if 25 <= X <= 53
--|> -> float 4 bytes
--|> -> double 8 bytes
--|> -> double precision 8 bytes
--|> -> real 8 bytes
--|> -> decimal(M,D) M+2 bytes if D > 0, M+1 bytes if D = 0 (D+2, if M < D)
--|> -> numeric(M,D) M+2 bytes if D > 0, M+1 bytes if D = 0 (D+2, if M < D)
--|> -> date 3 bytes (0000-00-00)
--|> -> datetime 8 bytes (0000-00-00 00:00:00)
--|> -> timestamp 4 bytes (00000000000000 length depends on display size)
--|> -> time 3 bytes (00:00:00)
--|> -> year 1 byte (0000)
3-> load data local infile "filename" into table tablename;
--> insert into pet values (data1,data2,...);
4-> select fieldname1 [as labelname1], ... from tablename [where datacondition [{and|or} ...]];
5-> update tablename set fieldname=expressão,[...] [where datacondition [{and|or} ...]];
6-> delete from tablename [where datacondition [{and|or}]];