Mysql
 sql >> Base de données >  >> RDS >> Mysql

Installez plusieurs instances MySQL sur un serveur Linux - utilisez un fichier de configuration MySQL distinct

curl -L -O https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.23-el7-x86_64.tar

[root]# rpm -qa|grep mysql
[root]# rpm -qa |grep mariadb-libs
yum supprimer mariadb-libs -y

tar -xvf mysql-8.0.23-el7-x86_64.tar

[root]# groupadd mysql
[root]# useradd -r -g mysql -s /bin/false mysql

[root]# cd /usr/local/
[root local]# tar xzvf /root/mysql-8.0.23-el7-x86_64.tar.gz

sudo ln -s /usr/local/mysql-8.0.23-el7-x86_64/ mysql

mkdir -p /mysql/{3306,3307,3308,3309}/data
chown -R mysql:mysql /mysql
cd /mysql

Exemple 1 (3306)

[mysqld]port =3306
basedir=/usr/local/mysql/
datadir=/mysql/3306/data
lower_case_table_names=1
innodb_buffer_pool_size=128M
socket =/tmp/mysql_3306.sock
log_error=/mysql/3306/data/mysql06.log

Exemple 2 (3307)

[mysqld]port =3307
basedir=/usr/local/mysql/
datadir=/mysql/3307/data
lower_case_table_names=1
innodb_buffer_pool_size=128M
socket =/tmp/mysql_3307.sock
log_error=/mysql/3307/data/mysql07.log

Exemple 3 (3308)

[mysqld]port =3308
basedir=/usr/local/mysql/
datadir=/mysql/3308/data
lower_case_table_names=1
innodb_buffer_pool_size=128M
socket =/tmp/mysql_3308.sock
log_error=/mysql/3308/data/mysql08.log

3306
/usr/local/mysql/bin/mysqld –defaults-file=/mysql/3306/my.cnf –initialize –basedir=/usr/local/mysql/ –datadir=/mysql/3306/data

3307
/usr/local/mysql/bin/mysqld –defaults-file=/mysql/3307/my.cnf –initialize –basedir=/usr/local/mysql/ –datadir=/mysql/3307/data

3308
/usr/local/mysql/bin/mysqld –defaults-file=/mysql/3308/my.cnf –initialize –basedir=/usr/local/mysql/ –datadir=/mysql/3308/data

ln -s /usr/local/mysql/bin/mysqld /usr/bin

[root]# vi /etc/profile
ou vi .bash_profile
# Ajoutez les informations suivantes à la fin du fichier
export PATH=$PATH:/usr/local/mysql/bin

#Faire en sorte que les variables d'environnement prennent effet
[root]# source /etc/profile

# Après le test, certaines des permissions de fichiers nouvellement générées par mysql lors de l'initialisation sont root, il est donc préférable d'autoriser à nouveau le chemin datadir vers mysql avant de démarrer
chown -R mysql:mysql /mysql

nohup /usr/local/mysql/bin/mysqld –defaults-file=/mysql/3306/my.cnf –user=mysql &
nohup /usr/local/mysql/bin/mysqld –defaults-file=/ mysql/3307/my.cnf –user=mysql &
nohup /usr/local/mysql/bin/mysqld –defaults-file=/mysql/3308/my.cnf –user=mysql &

ps -ef| grep mysql

netstat -ntl

#Modifier le mot de passe pour toutes les instances une par une :
mysql -S /tmp/mysql_3306.sock -p
#entrer le mot de passe temporaire à partir du journal :

modifier l'utilisateur 'root'@'localhost' identifié par 'Not_so_secure1!';

pour arrêter une instance
[[email protected] bin]# pwd
/usr/local/mysql/bin
[[email protected] bin]# ./mysqladmin -h127.0.0 .1 -uroot -p -P3306 shutdown
Entrez le mot de passe :

[email protected] bin]# ps -ef| grep mysql
mysql 22218 21246 0 11:56 pts/1 00:00:03 /usr/local/mysql/bin/mysqld –defaults-file=/mysql/3307/my.cnf –user=mysql
mysql 22259 21246 0 11:56 pts/1 00:00:03 /usr/local/mysql/bin/mysqld –defaults-file=/mysql/3308/my.cnf –user=mysql
root 22673 21537 0 12:24 pts/2 00:00:00 mysql -S /tmp/mysql_3306.sock -p
root 22705 21537 0 12:26 pts/2 00:00:00 grep –color=auto mysql