Cómo Instalar MySQL en Ubuntu
Ubuntu es un sistema operativo basado en GNU/Linux, y MySQL es un sistema de administración de bases de datos de código abierto. Cuando se juntan estas dos herramientas, construyes un entorno óptimo para un desarrollo web bien organizado.
A continuación se muestran los pasos necesarios para instalar MySQL en Ubuntu:
Paso 1: Instalar los paquetes necesarios
Los usuarios que usen la línea de comandos deberán instalar los paquetes ‘mysql-server’ y ‘mysql-client’ para estar preparados para la configuración. Esto se puede hacer usando el administrador de paquetes APT, ejecutando lo siguiente en una terminal:
sudo apt-get install mysql-server mysql-client
Paso 2: Configurar la instalación de MySQL
Después de la intalación, se le preguntará al usuario por una contraseña para el usuario root. Es importante recordar esta contraseña. Además, hay que asegurarse de que se seleccione ‘Yes’ cuando aparezca la opción ‘Configure the Validate Password Plugin’.
Paso 3: Iniciar y detener MySQL en el servidor
El servidor deberá iniciarse manualmente cada vez que se enciende la máquina. Esto significa que el usuario tendrá que acceder al servidor y ejecutar el siguiente comando:
sudo systemctl start mysql
Para detener, se deberá ejecutar el mismo comando, cambiando ‘start’ por ‘stop.’
Paso 4: Ejecutar las pruebas
Para probar la instalación, el usuario podrá acceder a MySQL por medio de la terminal y comprobar la versión ejecutando el siguiente comando:
mysql -V
También puede comprobar si el servidor está funcionando correctamente con:
systemctl status mysql
Consejos y advertencias
- Asegúrese de mantener la contraseña de root en un lugar seguro.
- Cree una cuenta de usuario para cada persona que acceda al servidor.
- Configure el firewall para bloquear la mayor cantidad de conexiones posibles.
How to install MySQL 5.7 in Ubuntu 20.04 using terminal?
How to Install MySQL 5.7 on Ubuntu 18.04, 20.04, or later 1 – Download and install MySQL server and client, 2 – Secure your MySQL root user account, 3 – Check the MySQL version, 4 – Add MySQL user and set privileges, 5 – Test MySQL 5.7, 6 – Log in to your MySQL server .
1 – Download and install MySQL server and client
To download and install the MySQL server and client, run the following command:
sudo apt-get update
sudo apt-get install mysql-server mysql-client -y
2 – Secure your MySQL root user account
By default, the root user has no password. To secure the root user account, run the following command and follow the on-screen instructions:
sudo mysql_secure_installation
3 – Check the MySQL version
After the installation, you can check the MySQL version to confirm you have successfully installed it:
sudo mysql –version
4 – Add MySQL user and set privileges
To create a new user and set the appropriate privileges, first connect to the MySQL server:
sudo mysql -u root -p
To create new user, run the following command:
CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘password’;
To grant the privileges to the new user, run:
GRANT ALL PRIVILEGES ON . TO ‘newuser’@’localhost’;
5 – Test MySQL 5.7
To check if MySQL is running and connected, run the following command:
sudo systemctl start mysql
6 – Log in to your MySQL server
Finally, you can now log in to the MySQL server with the new user’s credentials:
mysql -u newuser -p
How to install MySQL in terminal?
Installing MySQL Shell with the MySQL APT Repository Update package information for the MySQL APT repository: sudo apt-get update, Update the MySQL APT repository configuration package with the following command: sudo apt-get install mysql-apt-config, Install MySQL Shell with this command: sudo apt-get install mysql-shell .This will install MySQL Shell and any necessary dependencies.
How to install and configure MySQL in Ubuntu?
How to Install and Configure MySQL on Ubuntu Step 1: MySQL Client Installation. Install the mysql-client to remotely connect with the server: sudo apt install mysql-client -y, Step 2: MySQL Server Installation, Step 3: MySQL Configuration, Step 4: MySQL User Authentication Adjustments , Step 5: Update MySQL Root Password
Step 1: MySQL Client Installation
First, we’ll install the MySQL client which will be used to connect to the server.
Run the following command to install MySQL client:
sudo apt install mysql-client -y
Step 2: MySQL Server Installation
After the mysql-client is installed, we’ll install the server software. This will be the database management engine and constants for all the databases that we’ll be using.
Enter the following command to install MySQL Server:
sudo apt install mysql-server -y
A dialog will appear to confirm your choice and also prompt you with some configuration options, such as setting and confirming a root password.
It’s important to select a strong password for root as this will be the main admin user for your MySQL installation.
Step 3: MySQL Configuration
Now that we have MySQL installed, we need to configure it. This includes setting a binding address which is the IP address that MySQL should listen on and that incoming connections should connect to.
Edit the configuration file by running:
sudo nano /etc/mysql/my.cnf
In the configuration file, look for a line that starts with bind-address and make sure it matches the server’s IP address. If this line does not exist, add it at the bottom of the file.
Save and close the file.
Step 4: MySQL User Authentication Adjustments
Next, we’ll make sure that the default authentication for the root user is secure.
Open the MySQL configuration file:
sudo nano /etc/mysql/my.cnf
Uncomment the line that starts with “skip-grant-tables” by removing the “#” character.
Save and close the configuration file.
Step 5: Update MySQL Root Password
Now that the authentication configuration is in place, we’ll set a secure root password. Run the following command to login to the mysql shell as the root user:
sudo mysql -u root
This will take you directly to the MySQL prompt.
At the prompt, run these commands to reset the root password:
FLUSH PRIVILEGES;
SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘YOUR-NEW-PASSWORD’);
The first command will flush the existing user privileges and the second will set the password for the root user. Make sure to replace ‘YOUR-NEW-PASSWORD’ with a secure password of your own.
Finally, close the MySQL shell by typing q.
Your MySQL installation and configuration is now complete. You can now use the root user and password you have configured to maintain and manage MySQL databases.