GNU/Linux >> Tutoriales Linux >  >> Linux

Cómo instalar MySQL en Linux


La mayoría de las distribuciones de Linux vienen con MySQL. Si quieres usar MySQL, mi recomendación es que descargues la última versión de MySQL y la instales tú mismo. Más tarde, puede actualizarlo a la última versión cuando esté disponible. En este artículo, explicaré cómo instalar la última edición comunitaria gratuita de MySQL en la plataforma Linux.

1. Descargue la última versión estable de MySQL

Descargue mySQL desde mysql.com. Descargue la edición comunitaria de MySQL para su plataforma Linux adecuada. Descargué el "Red Hat Enterprise Linux 5 RPM (x86)". Asegúrese de descargar MySQL Server, Client y "Headers and library" desde la página de descarga.

  • Comunidad-cliente-MySQL-5.1.25-0.rhel5.i386.rpm
  • Comunidad-del-servidor-MySQL-5.1.25-0.rhel5.i386.rpm
  • MySQL-devel-community-5.1.25-0.rhel5.i386.rpm

2. Elimine el MySQL predeterminado existente que vino con la distribución de Linux

No realice esto en un sistema en el que alguna aplicación utilice la base de datos MySQL.

[local-host]# rpm -qa | grep -i mysql
mysql-5.0.22-2.1.0.1
mysqlclient10-3.23.58-4.RHEL4.1

[local-host]# rpm -e mysql --nodeps
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
[local-host]# rpm -e mysqlclient10

3. Instale el paquete MySQL descargado

Instale los paquetes MySQL Server y Client como se muestra a continuación.

[local-host]# rpm -ivh MySQL-server-community-5.1.25-0.rhel5.i386.rpm MySQL-client-community-5.1.25-0.rhel5.i386.rpm
Preparing...                ########################################### [100%]
1:MySQL-client-community ########################################### [ 50%]
2:MySQL-server-community ########################################### [100%]

Esto también mostrará el siguiente resultado e iniciará el demonio MySQL automáticamente.

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h medica2 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available at http://www.mysql.com/
Support MySQL by buying support/licenses from http://shop.mysql.com/

Starting MySQL.[  OK  ]
Giving mysqld 2 seconds to start

Instale el "Encabezado y las bibliotecas" que forman parte de los paquetes de desarrollo de MySQL.

[local-host]# rpm -ivh MySQL-devel-community-5.1.25-0.rhel5.i386.rpm
Preparing...                ########################################### [100%]
1:MySQL-devel-community  ########################################### [100%]

Nota: Cuando estaba compilando PHP con la opción MySQL desde la fuente en el sistema Linux, falló con el siguiente error. La instalación del paquete MySQL-devel-community solucionó este problema al instalar PHP desde la fuente.

configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!

4. Realice actividades de seguridad posteriores a la instalación en MySQL.

Como mínimo, debe establecer una contraseña para el usuario root como se muestra a continuación:

[local-user]# /usr/bin/mysqladmin -u root password 'My2Secure$Password'

La mejor opción es ejecutar el script mysql_secure_installation que se encargará de todos los elementos típicos relacionados con la seguridad en MySQL, como se muestra a continuación. En un alto nivel, esto hace los siguientes elementos:

  • Cambiar la contraseña raíz
  • Eliminar el usuario anónimo
  • Prohibir el inicio de sesión raíz desde máquinas remotas
  • Eliminar la base de datos de prueba de muestra predeterminada
[local-host]# /usr/bin/mysql_secure_installation

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.
You already have a root password set, so you can safely answer 'n'.
Change the 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] 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] 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!

5. Verifique la instalación de MySQL:

Puede verificar la versión instalada de MySQL ejecutando mysql -V como se muestra a continuación:

[local-host]# mysql -V
mysql  Ver 14.14 Distrib 5.1.25-rc, for redhat-linux-gnu (i686) using readline 5.1

Conéctese a la base de datos MySQL usando el usuario raíz y asegúrese de que la conexión sea exitosa.

[local-host]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Siga los pasos a continuación para detener e iniciar MySQL

[local-host]# service mysql status
MySQL running (12588)                                      [  OK  ]
[local-host]# service mysql stop
Shutting down MySQL.                                       [  OK  ]
[local-host]# service mysql start
Starting MySQL.                                            [  OK  ]

Linux
  1. Instalar MariaDB o MySQL en Linux

  2. Cómo instalar ifconfig en CentOS 7 Linux

  3. Cómo instalar MySQL 5.7 en Amazon Linux

  4. NordPass:un potente administrador de contraseñas para Linux

  5. ¿Cómo instalar MySQL en CentOS 7.x?

Cómo instalar MySQL en Ubuntu Linux

Cómo instalar MySQL 8.0 en Ubuntu 18.04

CÓMO:Ejecutar Linux en Android sin root

Cómo instalar MySQL 8.0 en Rocky Linux 8

Cómo instalar MySQL 8.0 en Ubuntu 18.04

Cómo instalar Mattermost en Rocky Linux 8