Rapid deployment of Centos/MySQL/Python environment

Centos7 installs MySQL 8 database

(yum, the default interpreter is python2.7, don't change Python soft connection)

mkdir /data
mkdir /data/mysql
cd /data/mysql
wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
yum -y install mysql80-community-release-el7-2.noarch.rpm
yum -y install mysql-community-server

If it is centos8, an error will be generated because there is a MySQL module locally. At this time, you can disable the module before trying to install:

yum module disable mysql

MySQL installation acceleration

If Yum - y install MySQL community server installation is extremely slow, you can take the following measures.
Downloaded cache path:


Use sftp tool to upload the complete package corresponding to the directory to this path, and then re execute the installation instruction.

Go to the image resource station to download (choose one)

  1. China University of science and technology
  2. Netease

Copy the name in the cache directory, search (usually the largest MySQL community server), download it, and upload it to the cache directory.

MySQL installation error

Note that the following errors generally do not occur. In case of errors, it is recommended to recheck the download package and server.

After downloading, if you encounter errors during installation, the following are reported:

Error: GPG check FAILED

Generally, dnf or yum software installation fails due to source key error.
Try adding the – nogpgcheck suffix to ignore and re execute the installation:

yum -y install mysql-community-server --nogpgcheck

Start database

systemctl start  mysqld.service

Modify the initial password of the database

Get initial password:

grep "password" /var/log/mysqld.log

Execute the following instructions and enter the default password to enter mysql

mysql -u root -p

To change the password, take passwd as an example:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'passwd';

Uninstall yum repository

yum -y remove mysql80-community-release-el7-2.noarch

mysql database is open to the public

use mysql; 
update user set host = '%' where user = 'root'; 
select host, user from user; 
flush privileges;

Modify mysql password strength

View password rules

SHOW VARIABLES LIKE 'validate_password%';

Set password strength

set global validate_password.policy=0;
set global validate_password.length=4;

That is, the password only needs to meet four characters (do not repeat with the user name)

View mysql code

show variables like '%set%';

Centos7 installing python3

Installation dependency

View gcc version

gcc --version

Not installed

yum -y install gcc

Installation dependency (important!)

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

setup script

Create a folder to store Python 3

mkdir /usr/local/python3.9

Download the specified version of python to the local

Manual Download:

  1. https://www.python.org/downloads/
  2. https://www.python.org/ftp/python/

Automatic download:

wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz

Download the package to linux, taking / data as an example

cd /data
tar -zxvf Python-3.9.9.tgz
cd Python-3.9.9.tgz
./configure --prefix=/usr/local/python3.9
make && make install

Establish a soft connection (do not replace the default python!)

If you enter Python and enter the 2.7 environment by default, please do not change the soft connection of python, which will cause inexplicable errors in centos.

In fact, the system environment variable of Python should be established here, not just a soft link. But centos has installed python2 by default, so only a soft link is established here.

If the soft connection already exists, use rm to delete it.

ln -s /usr/local/python3.9/bin/python3.9 /usr/bin/python3
ln -s /usr/local/python3.9/bin/pip3.9 /usr/bin/pip3

Establish pip soft connection

ln -s /usr/bin/pip3 /usr/bin/pip

View established soft connections

ls -il /usr/bin/pip

Python creates virtualenv virtual environment


pip install virtualenv

View version

virtualenv --version

Enter virtual environment

Go to the directory to be created and create the environment (venv can be changed to its own name)

virtualenv venv

Activate environment

source venv/bin/activate

Exit environment


Other related commands:

View the current virtual machine environment directory


Switch virtual environment

workon venv2

Exit virtual environment


Delete virtual environment

rmvirtualenv venv

Python installation requirements Txt dependency

Generate project dependencies

pipreqs ./  --encoding=utf8

Installation project dependency

Add requirements Txt copy to the project directory and install

pip install -r requirements.txt

Keywords: Python MySQL CentOS

Added by dave007 on Tue, 15 Feb 2022 07:42:16 +0200