0% found this document useful (0 votes)
192 views

Comandos MySQL

The document provides instructions for performing common SQL operations like connecting to a database, creating and selecting databases, showing and describing tables, inserting and selecting data from tables, updating and deleting rows, using variables, granting privileges to users, and more. It also includes examples of creating multiple tables and relationships between them by using foreign keys.

Uploaded by

Luis Gomez
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views

Comandos MySQL

The document provides instructions for performing common SQL operations like connecting to a database, creating and selecting databases, showing and describing tables, inserting and selecting data from tables, updating and deleting rows, using variables, granting privileges to users, and more. It also includes examples of creating multiple tables and relationships between them by using foreign keys.

Uploaded by

Luis Gomez
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

mysql> SHOW DATABASES; mysql> USE test Dar permisos aun usuario en una base de datos GRANT ALL

ON menagerie.* TO 'su_nombre_mysql'@'su_host_cliente'; Crear y seleccionar una base de datos mysql> CREATE DATABASE menagerie; mysql> USE menagerie Entrada rpida shell> mysql -h host -u user -p menagerie Mostrar tablas mysql> SHOW TABLES; Crear Tabla mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), -> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE); Verificar la estructura de la tabla mysql> DESCRIBE pet; Cargar datos en una tabla mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet -> LINES TERMINATED BY '\r\n'; mysql> INSERT INTO pet -> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL); Extraer informacin de una tabla SELECT seleccionar_Esto FROM desde_tabla WHERE condiciones; mysql> SELECT * FROM pet; mysql> DELETE FROM pet; mysql> UPDATE pet SET birth = '1989-08-31' WHERE name = 'Bowser'; Clculos sobre fechas mysql> SELECT name, birth, CURDATE(), -> (YEAR(CURDATE())-YEAR(birth)) -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5)) -> AS age -> FROM pet; mysql> SELECT name, birth, MONTH(birth) FROM pet; Utilizacin de variables de usuario mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop; mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price; Crear Varias Tablas CREATE TABLE person ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, name CHAR(60) NOT NULL, PRIMARY KEY (id) );

CREATE TABLE shirt ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, style ENUM('t-shirt', 'polo', 'dress') NOT NULL, color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL, owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id), PRIMARY KEY (id) ); INSERT INTO person VALUES (NULL, 'Antonio Paz'); SELECT @last := LAST_INSERT_ID(); INSERT (NULL, (NULL, (NULL, INTO shirt VALUES 'polo', 'blue', @last), 'dress', 'white', @last), 't-shirt', 'blue', @last);

INSERT INTO person VALUES (NULL, 'Lilliana Angelovska'); SELECT @last := LAST_INSERT_ID(); INSERT (NULL, (NULL, (NULL, (NULL, INTO shirt VALUES 'dress', 'orange', @last), 'polo', 'red', @last), 'dress', 'blue', @last), 't-shirt', 'white', @last);

SELECT * FROM person; CREATE TABLE prueba ( ID_Prueba int(11) NOT NULL auto_increment, Nombre varchar(100), Apellidos varchar(100), PRIMARY KEY (ID_Prueba), UNIQUE ID_Prueba (ID_Prueba) ); INSERT INSERT INSERT INSERT INTO INTO INTO INTO prueba prueba prueba prueba VALUES VALUES VALUES VALUES (NULL,'Antonio','Paz'); (NULL,'Pepito','Perez'); (NULL,'Alam','Brito'); (NULL,'Perencito','Cordoba');

SELECT * FROM PRUEBA; Dar Privilegios y crear usuarios mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' -> IDENTIFIED BY 'some_pass' WITH GRANT OPTION; mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%' -> IDENTIFIED BY 'some_pass' WITH GRANT OPTION; mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost'; mysql> GRANT USAGE ON *.* TO 'dummy'@'localhost';

You might also like