Comandos MYSQL

 
Pasos para Ingresar a MYSQL
  1. Ingresar al panel de control del XAMPP e inicializar el servidor Apache y el servidor de base de datos MYSQL.
  2. Ingresar y ejecutar el comando CMD, es de anotar que debe quedar en el  disco C:/
  3.  Escribimos el patch o ruta asi: cd/xampp/mysql/bin
  4. Escribimos el patch o ruta para que nos aparezca e ingresemos el usuario y contraseña asi: c:/xampp/mysql/bin>mysql -uroot -p
  5. Nos va aparecer ya el servidor de MYSQL.
COMANDOS PARA CREAR UNA BASE DE DATOS
 
Microsoft Windows [Versión 6.3.9600]
(c) 2013 Microsoft Corporation. Todos los derechos reservados.
 
C:\Users\01064-10>cd/xampp/mysql/bin
 
C:\xampp\mysql\bin>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.21 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> show databases;
 +--------------------+
| Database           |
+--------------------+
| information_schema |
| cdcol              |
| mysql              |
| performance_schema |
| phpmyadmin         |
| test               |
| webauth            |
+--------------------+
7 rows in set (0.14 sec)
mysql> create database biblioteca;
Query OK, 1 row affected (0.05 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| biblioteca         |
| cdcol              |
| mysql              |
| performance_schema |
| phpmyadmin         |
| test               |
| webauth            |
+--------------------+
8 rows in set (0.00 sec)
 
mysql> use biblioteca;
Database changed
mysql> show tables;
Empty set (0.00 sec)
 
mysql> create table libro
    -> (cod_lib char(10) not null primary key,
    -> nom_lib char(40) not null);
Query OK, 0 rows affected (4.14 sec)
 
mysql> create table autor
    -> (cod_aut char(20) not null primary key,
    -> nombre char(40) not null);
Query OK, 0 rows affected (0.27 sec)
mysql> show tables;
+----------------------+
| Tables_in_biblioteca |
+----------------------+
| autor                |
| libro                |
+----------------------+
2 rows in set (0.02 sec)
 
mysql> describe libro;
+---------+----------+------+-----+---------+-------+
| Field   | Type     | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| cod_lib | char(10) | NO   | PRI | NULL    |       |
| nom_lib | char(40) | NO   |     | NULL    |       |
+---------+----------+------+-----+---------+-------+
2 rows in set (0.20 sec)
mysql> describe autor;
+---------+----------+------+-----+---------+-------+
| Field   | Type     | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| cod_aut | char(20) | NO   | PRI | NULL    |       |
| nombre  | char(40) | NO   |     | NULL    |       |
+---------+----------+------+-----+---------+-------+
2 rows in set (0.05 sec)
 
mysql> create table lib_aut
    -> (cod_lib char(10) not null,
    -> cod_aut char(10) not null,
    -> foreign key(cod_lib) references libro(cod_lib) on delete cascade on updat
e cascade,
    -> foreign key(cod_aut) references autor(cod_aut) on delete cascade on updat
e cascade)engine=innodb;
Query OK, 0 rows affected (0.41 sec)
 
mysql> describe lib_aut;
+---------+----------+------+-----+---------+-------+
| Field   | Type     | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| cod_lib | char(10) | NO   | MUL | NULL    |       |
| cod_aut | char(10) | NO   | MUL | NULL    |       |
+---------+----------+------+-----+---------+-------+
2 rows in set (0.04 sec)
 
mysql> describe libro;
+---------+----------+------+-----+---------+-------+
| Field   | Type     | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| cod_lib | char(10) | NO   | PRI | NULL    |       |
| nom_lib | char(40) | NO   |     | NULL    |       |
+---------+----------+------+-----+---------+-------+
2 rows in set (0.02 sec)
 
mysql>
 
_________________________________________________________________
 
Ejercicio Nº 2
Microsoft Windows [Versión 6.3.9600]
(c) 2013 Microsoft Corporation. Todos los derechos reservados.
 
C:\Users\01065-14>cd/xampp/mysql/bin
 
C:\xampp\mysql\bin>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.21 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> show databases;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    1
Current database: *** NONE ***
 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cdcol              |
| mysql              |
| performance_schema |
| phpmyadmin         |
| test               |
| webauth            |
+--------------------+
7 rows in set (0.09 sec)
 
mysql> create database materias
 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cdcol              |
| mysql              |
| performance_schema |
| phpmyadmin         |
| test               |
| webauth            |
+--------------------+
7 rows in set (0.00 sec)
 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cdcol              |
| mysql              |
| performance_schema |
| phpmyadmin         |
| test               |
| webauth            |
+--------------------+
7 rows in set (0.00 sec)
 
mysql> create database materia;
Query OK, 1 row affected (0.00 sec)
 
mysql> create table estudiante
    -> (cod_est char(10) not null primary key,
    -> nom_est char(40) not null,
    -> dir_est char(40) not null,
    -> tel_est char(12) not null,
    -> email_est char(30) not null);
Query OK, 0 rows affected (0.41 sec)
 
mysql> create table materia
    -> (cod_mat char(10) not null primary key,
    -> nom_mat char(15) not null);
Query OK, 0 rows affected (0.28 sec)
 
mysql> create table mat_est
    -> (cod_est char(10) not null,
    -> cod_mat char(10) not null,
    -> foreign key (cod_est) references estudiante(cod_est)on delete cascade on
update cascade,
    -> foreign key (cod_mat) references materia(cod_mat)on delete cascade on upd
ate cascade)engine=innodb;
Query OK, 0 rows affected (0.41 sec)
 
mysql> show tables;
+-------------------+
| Tables_in_materia |
+-------------------+
| estudiante        |
| mat_est           |
| materia           |
+-------------------+
3 rows in set (0.00 sec)
 
mysql> describe estudiante;
+-----------+----------+------+-----+---------+-------+
| Field     | Type     | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| cod_est   | char(10) | NO   | PRI | NULL    |       |
| nom_est   | char(40) | NO   |     | NULL    |       |
| dir_est   | char(40) | NO   |     | NULL    |       |
| tel_est   | char(12) | NO   |     | NULL    |       |
| email_est | char(30) | NO   |     | NULL    |       |
+-----------+----------+------+-----+---------+-------+
5 rows in set (0.03 sec)
 
mysql> describe materia;
+---------+----------+------+-----+---------+-------+
| Field   | Type     | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| cod_mat | char(10) | NO   | PRI | NULL    |       |
| nom_mat | char(15) | NO   |     | NULL    |       |
+---------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)
 
mysql> describe mat_est;
+---------+----------+------+-----+---------+-------+
| Field   | Type     | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| cod_est | char(10) | NO   | MUL | NULL    |       |
| cod_mat | char(10) | NO   | MUL | NULL    |       |
+---------+----------+------+-----+---------+-------+
2 rows in set (0.02 sec)
 
mysql>