GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come installare e configurare mysql 8 su Ubuntu 20.04

MySQL è uno dei popolari sistemi di gestione di database relazionali open source. Viene comunemente installato come parte del popolare stack LAMP o LEMP (Linux, Apache/Nginx, MySQL/MariaDB, PHP/Python/Perl).

Contenuti correlati

  • Come installare Mysql 8 su Rocky Linux/Centos 8
  • Come installare e configurare Mysql Server 8 su Fedora 34/35
  • Autorizzazioni MySQL:crea, aggiorna, elimina utenti del database
  • Come eseguire Mysql 8 con Docker e Docker-Compose
  • Installa e configura Nginx, WordPress e Mysql 8 in Centos 8
  • Crea un'istanza RDS in terraform con un esempio Mariadb
  • Utilizzo di Ansible per installare e inizializzare Mysql 8 su Centos 8

Prerequisiti

Per seguire questa guida, assicurati di avere quanto segue:

  1. Ubuntu Server 20.04 aggiornato con accesso a Internet
  2. Accesso root al server o utente con accesso sudo

Passaggi per installare MySQL 8

  1. Assicurati che il nostro server Ubuntu sia aggiornato
  2. Configura il repository per l'installazione di MySQL 8
  3. Installa il server MySQL 8
  4. Verifica la connessione a mysql con la password di root

1. Assicurati che il nostro server Ubuntu sia aggiornato

Prima di procedere, assicuriamoci che il server Ubuntu sia aggiornato. Prima aggiorna i repository, quindi esegui un aggiornamento del sistema per assicurarti che tutti i pacchetti installati siano aggiornati:

Nel tuo terminale, digita questi. Il -y opzione in apt upgrade è garantire che il sistema non si interrompa per accettare l'aggiornamento.

$ sudo apt update
$ sudo apt upgrade -y

2. Configura il repository per l'installazione di MySQL 8

Il server MySQL 8 non è disponibile nei repository Ubuntu predefiniti. Il team di mysql fornisce un .deb scaricabile file che configurerà i repository per l'installazione di mysql server 8. Scaricalo con questo comando:

curl -LO https://dev.mysql.com/get/mysql-apt-config_0.8.19-1_all.deb

Dovresti vedere un output quasi simile a questo:

$ curl -LO https://dev.mysql.com/get/mysql-apt-config_0.8.19-1_all.deb
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 35536  100 35536    0     0  55874      0 --:--:-- --:--:-- --:--:-- 55874

Una volta terminato il download, è necessario installare il file deb scaricato. Usa questo comando per installare:

sudo dpkg -i ./mysql-apt-config_0.8.19-1_all.deb

Si aprirà una finestra di configurazione che ti chiederà di scegliere la versione del server MySQL e altri componenti come cluster, librerie client condivise o il workbench MySQL.

Per ora poiché siamo interessati solo all'installazione di Mysql Server, lascia le impostazioni predefinite e fai clic su OK per procedere.

Questo è l'output in caso di installazione e configurazione riuscite.

$ sudo dpkg -i ./mysql-apt-config_0.8.19-1_all.deb
(Reading database ... 91535 files and directories currently installed.)
Preparing to unpack .../mysql-apt-config_0.8.19-1_all.deb ...
Unpacking mysql-apt-config (0.8.19-1) over (0.8.19-1) ...
Setting up mysql-apt-config (0.8.19-1) ...
Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
OK

3. Installa il server MySQL 8

Ora che i repository sono stati aggiunti per includere il server mysql, ora possiamo installare il pacchetto mysql-server.
Per prima cosa, aggiorna i repository per ottenere le ultime novità dal repository aggiunto:

$ sudo apt update

Quindi installa Mysql 8 Server usando questo comando:

sudo apt install -y mysql-server

Inserisci le tue credenziali di amministratore e il sistema installerà il pacchetto del server MySQL, i pacchetti client e i file comuni del database.

L'installazione ti chiederà di inserire e confermare un utente root e una password per il database MySQL.

Successivamente ti verrà chiesto di selezionare il plug-in di autenticazione. Si consiglia di scegliere di utilizzare una password complessa:

Dopodiché verrà impostata la nuova password e il servizio verrà ricaricato.

Conferma che il server mysql è attivo e funzionante con questo comando:

$ sudo systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-09-28 13:08:22 UTC; 2min 23s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 45123 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 45173 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 4710)
     Memory: 353.0M
     CGroup: /system.slice/mysql.service
             └─45173 /usr/sbin/mysqld

Sep 28 13:08:21 ip-172-26-11-229 systemd[1]: Starting MySQL Community Server...
Sep 28 13:08:22 ip-172-26-11-229 systemd[1]: Started MySQL Community Server.

Il Active: active (running) since ... la parte in alto mostra che l'app è attiva e funzionante.

4. Testare la connessione a mysql con la password di root

Ora che mysql è tutto configurato ed è in esecuzione, dobbiamo confermare che può accettare connessioni.

Per testare, connettiti a mysql con l'utente root – mysql -h 127.0.0.1 -u root -p

Uscita:

$ mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>

Controlla la versione di MySQL per confermare che tutto sia a posto:

mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.26    |
+-----------+
1 row in set (0.00 sec)

5. Extra – Creazione di utenti in mysql

Per connettersi in remoto a mysql, si consiglia di creare un utente specifico dell'app e un database. Facciamolo qui.

Per creare un database, utilizzare questo comando nel prompt di mysql; Questo comando crea un. database chiamato citizix_db .

create database citizix_db;

Per creare un utente, usalo nel prompt di mysql; questo comando creerà un utente citizix_user che può connettersi da qualsiasi luogo con la password specificata:

create user 'citizix_user'@'%' identified by 'S0mStrongPa$word';

Ora concedi all'utente creato tutti i privilegi sul database creato:

grant all privileges on citizix_db.* to 'citizix_user'@'%';

Conferma che puoi connetterti come nuovo utente. Usa mysql comando sul terminale specificando l'host con -h e utente con -u . Fornisci anche il flag di richiesta password -p quindi inserire la password:

❯ mysql -h 192.168.10.20 -u citizix_user -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>

Conferma i permessi che abbiamo usando questi comandi:

mysql> show grants;
+--------------------------------------------------------------+
| Grants for [email protected]%                                    |
+--------------------------------------------------------------+
| GRANT USAGE ON *.* TO `citizix_user`@`%`                     |
| GRANT ALL PRIVILEGES ON `citizix_db`.* TO `citizix_user`@`%` |
+--------------------------------------------------------------+
2 rows in set (0.44 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| citizix_db         |
| information_schema |
+--------------------+
2 rows in set (0.22 sec)

mysql>

Fino a questo punto, siamo stati in grado di installare mysql server 8 su Ubuntu 20.04 e abbiamo testato che funziona come previsto aggiungendo un utente e un database.


Ubuntu
  1. Come installare MySQL 8.0 in Ubuntu 18.04

  2. Come installare e proteggere phpMyAdmin su Ubuntu

  3. Come installare PHP 7.4 e 8.0 su Ubuntu 18.04 o 20.04

  4. Come installare Anaconda su Ubuntu 18.04 e 20.04

  5. Come installo e configuro Git su Ubuntu?

Come installare il server MySQL in Ubuntu

Come installare uTorrent in Ubuntu 18.04 e Ubuntu 19.04

Come installare TeamViewer 12 su Ubuntu 16.04 e Ubuntu 16.10

Come installare ScreenCloud su Ubuntu 16.04 e Ubuntu 17.04

Come installare e configurare MySQL su Ubuntu 18.04

Come installare MySQL su Ubuntu 22.04