GNU/Linux >> Linux Esercitazione >  >> Linux

Come installare MySQL su Linux


La maggior parte delle distribuzioni Linux viene fornita con MySQL. Se vuoi usare MySQL, il mio consiglio è di scaricare l'ultima versione di MySQL e installarla tu stesso. Successivamente puoi aggiornarlo all'ultima versione quando diventa disponibile. In questo articolo spiegherò come installare l'ultima edizione gratuita della community di MySQL su piattaforma Linux.

1. Scarica l'ultima versione stabile di MySQL

Scarica mySQL da mysql.com. Scarica l'edizione della community di MySQL per la tua piattaforma Linux appropriata. Ho scaricato "Red Hat Enterprise Linux 5 RPM (x86)". Assicurati di scaricare MySQL Server, Client e "Intestazioni e librerie" dalla pagina di download.

  • MySQL-client-community-5.1.25-0.rhel5.i386.rpm
  • MySQL-server-community-5.1.25-0.rhel5.i386.rpm
  • MySQL-devel-community-5.1.25-0.rhel5.i386.rpm

2. Rimuovere il MySQL predefinito esistente fornito con la distribuzione Linux

Non eseguire questa operazione su un sistema in cui il database MySQL viene utilizzato da qualche applicazione.

[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. Installa il pacchetto MySQL scaricato

Installa i pacchetti MySQL Server e Client come mostrato di seguito.

[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%]

Questo mostrerà anche il seguente output e avvierà automaticamente il demone MySQL.

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

Installa "Header and Libraries" che fanno parte dei pacchetti MySQL-devel.

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

Nota: Quando stavo compilando PHP con l'opzione MySQL dal sorgente sul sistema Linux, non è riuscito con il seguente errore. L'installazione del pacchetto MySQL-devel-community ha risolto questo problema nell'installazione di PHP dal sorgente.

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

4. Esegui attività di sicurezza post-installazione su MySQL.

Come minimo dovresti impostare una password per l'utente root come mostrato di seguito:

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

L'opzione migliore è eseguire lo script mysql_secure_installation che si occuperà di tutti gli elementi tipici relativi alla sicurezza su MySQL, come mostrato di seguito. Ad alto livello questo fa i seguenti oggetti:

  • Cambia la password di root
  • Rimuovi l'utente anonimo
  • Non consentire l'accesso come root da macchine remote
  • Rimuovi il database di test di esempio predefinito
[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. Verifica l'installazione di MySQL:

Puoi controllare la versione installata di MySQL eseguendo mysql -V come mostrato di seguito:

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

Connettiti al database MySQL utilizzando l'utente root e assicurati che la connessione sia riuscita.

[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>

Segui i passaggi seguenti per interrompere e avviare 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. Come installare MySQL 8.0 su Fedora 35 / Fedora 34

  2. Come installare MySQL 5.7 su Amazon Linux

  3. Come installare MySQL su Fedora 35

  4. Come installare MySQL su Ubuntu 18.04

  5. NordPass – Un potente gestore di password per Linux

Come installare MySQL in Ubuntu Linux

Come installare MySQL 8.0 su Ubuntu 18.04

HOWTO:eseguire Linux su Android senza root

Come installare MySQL 8.0 su Rocky Linux 8

Come installare MySQL 8.0 su Ubuntu 18.04

Come installare Mattermost su Rocky Linux 8