You are on page 1of 4

LABORATORIO

Servicio MYSQL
Objetivos:

 Configurar el servicio MySQL


 Seguridad del Servicio MySQL
 Backup y Restore de MySQL

Procedimiento
1. Realizar la instalación de los paquetes de la BD, de la siguiente forma:
# [root@srvmail ~]# yum install mariadb-server mariadb

2. Iniciar el servicio MySQL y habilitar el inicio desde el boot:


# systemctl enable mariadb.service && systemctl start mariadb.service

3. Iniciar la configuración de la base de datos de forma segúra


[root@station0 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client:
command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):Enter


OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y


New password:EXAMPLE2016
Re-enter new password: EXAMPLE2016
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MariaDB installation has an anonymous user, allowing


anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
... Success!

Normally, root should only be allowed to connect from 'localhost'.


This
ensures that someone cannot guess at the root password from the
network.

Disallow root login remotely? [Y/n] n


... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y


- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y


... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

4. Reiniciar y verificar el servicio de Base de Datos


[root@station0 conf.d]# systemctl stop mariadb
[root@station0 conf.d]# systemctl start mariadb
[root@station0 conf.d]# systemctl status mariadb
mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled)
Active: active (running) since Fri 2016-05-20 17:52:44 PET; 5s ago
Process: 9675 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID
(code=exited, status=0/SUCCESS)
Process: 9647 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
(code=exited, status=0/SUCCESS)
Main PID: 9674 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─9674 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─9833 /usr/libexec/mysqld --basedir=/usr --
datadir=/var/lib/mysql --pl...

May 20 17:52:42 station0.example.pe systemd[1]: Starting MariaDB


database server...
May 20 17:52:42 station0.example.pe mysqld_safe[9674]: 160520 17:52:42
mysqld_safe Lo....
May 20 17:52:43 station0.example.pe mysqld_safe[9674]: 160520 17:52:43
mysqld_safe St...l
May 20 17:52:44 station0.example.pe systemd[1]: Started MariaDB
database server.
Hint: Some lines were ellipsized, use -l to show in full.

5. Ingresar a la Base de Datos:


[root@station0 conf.d]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input
statement.

MariaDB [(none)]>

6. Creación de una BD:


#CREATE DATABASE <database-name> CHARACTER SET utf8 COLLATE utf8_general_ci;

#CREATE DATABASE ventas CHARACTER SET utf8 COLLATE utf8_general_ci;

7. Creación de un usuario para la administración de BD:


#CREATE USER 'fernando'@'localhost' IDENTIFIED BY 'fer_pass';

8. Otorgar permisos a una base de datos, usuario y host especifico.


#GRANT ALL ON <database-name>.* TO '<username>'@'localhost' IDENTIFIED BY
'<password>' WITH GRANT OPTION;

9. Crear tablas en la BD:


# CREATE TABLE contacto (
ID_Cont mediumint(8) unsigned default null auto_increment,
Nombre varchar(50) not null,
Email varchar(50) not null,
Telefono varchar(15) not null,
PRIMARY KEY (ID_Cont)
);

10. Insertar registros a la Base de Datos.

#INSERT INTO contacto (Nombre, Email, Telefono)


VALUES ('Rodolfo Barzola','rbarzola@gmail.com','982735527');
11. Actualizar los cambios.
# FLUSH PRIVILEGES;

12. Permisos para controlar los objetos de INSERT, SELECT, etc; en la base de datos.
#GRANT SELECT, INSERT, DELETE ON <database name>.* TO '<username>'@'localhost';

13. Visualizar los permisos de un Usuario.


#SHOW GRANTS FOR '<username>'@'localhost';

14. Realizar un Backup de BD.


# mysqldump -u root -p nombre_base_de_datos > fichero.sql

15. Ejecutar el backup de todas las bases de datos:


# mysqldump -u root -p --all-databases > fichero.sql

16. Si deseamos hacer un backup de una base de datos:


# mysqldump -u root -p --databases base_datos1 base_datos2 > fichero.sql

17. Ejecutar el restore de una BD.


# mysql -u root -p nombre_base_de_datos < fichero.sql

18. Ejecutar el restore de una sola Base de Datos, desde el backup completo de la BD.
# mysql --one-database database_name < all_databases.sql

You might also like