viernes, 5 de abril de 2013

Instalando MySQL en fedora 18

Los pasos salieron de: http://www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel/ el primer paso es acceder como superusuario
[miguel@dhcppc6 ~]$ sudo -i
[sudo] password for miguel:
A continuación se dan de alta los repositorios de rpmfusion
[root@dhcppc6 ~]# rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm 
[root@dhcppc6 ~]# rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
Ahora se van a habilitar los repositorios y ver las versiones disponibles de MySQL
[root@dhcppc6 ~]# yum --enablerepo=remi list mysql mysql-server
Ahora a instalar MySQL desde los repositorios
[root@dhcppc6 ~]# yum --enablerepo=remi install mysql mysql-server
Iniciando el servicio MySQL e instalando para su arranque automático con cada inicio de sesión
[root@dhcppc6 ~]# systemctl start mysqld.service
[root@dhcppc6 ~]# systemctl enable mysqld.service
ln -s '/usr/lib/systemd/system/mysqld.service' '/etc/systemd/system/multi-user.target.wants/mysqld.service'
[root@dhcppc6 ~]# 

Ahora se continúa con el "hardening" de la instalación de MySQL, 1. Instalación (cambio de la contraseña de root) 2. Retirar acceso a usuarios anónimos 3. Deshabilitar el acceso remoto como root 4. Remover la Base de datos de prueba y su acceso 5. Renovar la tabla de privilegios iniciar la instalación segura mediante el siguiente comando
[root@dhcppc6 ~]# /usr/bin/mysql_secure_installation
Al pulsar enter solicita la nueva contraseña de root
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, 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): 
OK, successfully used password, moving on...

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

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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] 
 ... 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] Y
 ... Success!

By default, MySQL 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 MySQL
installation should now be secure.

Thanks for using MySQL!

conectarse a la base de datos
[root@dhcppc6 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.5.30 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2013, 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> 

Creación de una base de datos, un usuario y la habilitación de conexiones remotas a una base datos MySQL Los parámetros que se proponen son:

  • DB_NAME = webdb 
  • USER_NAME = webdb_user 
  • REMOTE_IP = 10.0.15.25 
  • PASSWORD = password123 
  • PERMISIONS = ALL

## CREATE DATABASE ##
mysql> CREATE DATABASE webdb;
 
## CREATE USER ##
mysql> CREATE USER 'webdb_user'@'10.0.15.25' IDENTIFIED BY 'password123';
 
## GRANT PERMISSIONS ##
mysql> GRANT ALL ON webdb.* TO 'webdb_user'@'10.0.15.25';
 
##  FLUSH PRIVILEGES, Tell the server TO reload the GRANT TABLES  ##
mysql> FLUSH PRIVILEGES;
 
ahora, el acceso en mi caso solo lo podía hacer por medio de root, con la orden sudo, sin embargo, con mi usuario habitual, aunque colocaba correctamente el password de root de mysql no podia acceder, ni de consola ni por phpMyAdmin, entonces para corregir esto:
 1. agregar a mi usuario al grupo mysql, en KDE, Inicio-; Aplicaciones - Administración - usuarios y grupos (requiere contraseña de administrador)

2. Ya en el entorno, quitar el check, de la opción "Ocultar grupos del sistema" en Preferencias del menú Editar

3. ir a la pestaña grupos, dar clic sobre mysql y clic en el botón Propiedades.

4. Selecciona a tu usuario habitual o normal, o como lo quieras llamar.

5. Cerrar el sistema y probar desde una consola Si nuevamente obtienes error de acceso, entonces gracias a la siguiente página vi la luz http://my.opera.com/FastTigerBlog/blog/solucion-al-problema-mysql-u-root-p
*******************************************************************************
1. Detener el servicio mysql, recuerda que estoy en fedora18 usando mysql del repo rpmfusion (http://www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel/)
systemctl stop mysqld.service
2. brincarnos el passwd de root
/usr/bin/mysqld_safe --user=mysql --skip-grant-tables
3. Abre otra terminal y teclea en ella
[miguel@dhcppc6 ~]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.30 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2013, 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>
4. ahora hacemos uso de la tabla mysql use mysql; 5. Se realiza la actualización del passwd de root de mysql
mysql> update user set Password=PASSWORD('xxxxxxxx') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
6. salimos exit; 7. Detenemos la consola de modo seguro (cierra la consola) 8. Re arranca el servicio mysql
[miguel@dhcppc6 ~]$ sudo -i
[sudo] password for miguel: 
[root@dhcppc6 ~]# systemctl start mysqld.service
[root@dhcppc6 ~]# exit
logout

9. Reinicia la sesion nueva de mysql con la contraseña nueva de root
[miguel@dhcppc6 ~]$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.30 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2013, 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>