GNU/Linux >> Tutoriels Linux >  >> Linux

Comment installer MySQL sur Linux


La plupart des distributions Linux sont livrées avec MySQL. Si vous souhaitez utiliser MySQL, je vous recommande de télécharger la dernière version de MySQL et de l'installer vous-même. Plus tard, vous pourrez le mettre à niveau vers la dernière version lorsqu'elle sera disponible. Dans cet article, je vais vous expliquer comment installer la dernière édition communautaire gratuite de MySQL sur la plate-forme Linux.

1. Téléchargez la dernière version stable de MySQL

Téléchargez mySQL depuis mysql.com . Veuillez télécharger l'édition communautaire de MySQL pour votre plate-forme Linux appropriée. J'ai téléchargé le "Red Hat Enterprise Linux 5 RPM (x86)". Assurez-vous de télécharger MySQL Server, Client et "En-têtes et bibliothèques" depuis la page de téléchargement.

  • 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. Supprimez le MySQL par défaut fourni avec la distribution Linux

N'effectuez pas cette opération sur un système où la base de données MySQL est utilisée par une application.

[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. Installez le package MySQL téléchargé

Installez les packages MySQL Server et Client comme indiqué ci-dessous.

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

Cela affichera également la sortie suivante et démarrera automatiquement le démon 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

Installez "l'en-tête et les bibliothèques" qui font partie des packages MySQL-devel.

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

Remarque : Lorsque je compilais PHP avec l'option MySQL à partir de la source sur le système Linux, cela a échoué avec l'erreur suivante. L'installation du package MySQL-devel-community a résolu ce problème lors de l'installation de PHP à partir des sources.

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

4. Effectuez des activités de sécurité post-installation sur MySQL.

Au minimum, vous devez définir un mot de passe pour l'utilisateur root comme indiqué ci-dessous :

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

La meilleure option consiste à exécuter le script mysql_secure_installation qui s'occupera de tous les éléments typiques liés à la sécurité sur MySQL, comme indiqué ci-dessous. À un niveau élevé, cela fait les éléments suivants :

  • Modifier le mot de passe root
  • Supprimer l'utilisateur anonyme
  • Interdire la connexion root à partir de machines distantes
  • Supprimer l'exemple de base de données de test par défaut
[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. Vérifiez l'installation de MySQL :

Vous pouvez vérifier la version installée de MySQL en exécutant mysql -V comme indiqué ci-dessous :

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

Connectez-vous à la base de données MySQL en utilisant l'utilisateur root et assurez-vous que la connexion est réussie.

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

Suivez les étapes ci-dessous pour arrêter et démarrer 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. Installer MariaDB ou MySQL sur Linux

  2. Comment installer ifconfig sur CentOS 7 Linux

  3. Comment installer MySQL 5.7 sur Amazon Linux

  4. Comment installer MySQL sur Fedora 35

  5. Comment installer MySQL sur Ubuntu 22.04

Comment installer MySQL dans Ubuntu Linux

Comment installer MySQL 8.0 sur Ubuntu 18.04

HOWTO :Exécuter Linux sur Android sans racine

Comment installer MySQL 8.0 sur Rocky Linux 8

Comment installer MySQL 8.0 sur Ubuntu 18.04

Comment installer Mattermost sur Rocky Linux 8