Install MySQL and python3 in CentOS7

Posted by aquilina on Sat, 05 Feb 2022 09:44:19 +0100

Write it in the front, and put all the software packages in the back under / opt/software / and install them under / opt/apps /

1. Install mysql8

1.1 resources

Link: https://pan.baidu.com/s/1csFQM-T_FATThGuw2rmOAA
Extraction code: good

1.2 check whether the virtual machine has mariadb

CentOS7 generally has a data mariadb of its own MySQL system. You need to uninstall it first and execute the following commands in sequence

rpm -qa|grep mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
rpm -qa|grep mariadb

1.3 download mysql8 and put it under / opt/software / and start building

# Unzip the MySQL 8 installation package
tar -zxvf mysql-8.0.21-el7-x86_64.tar.gz
# Rename and move
mv mysql-8.0.21-el7-x86_64 mysql8
mv mysql8 /opt/apps/
# Enter the mysql8 directory and create the mysql8 data file storage directory
cd /opt/apps/mysql8/
mkdir mysqldb
# Create MySQL groups and users
groupadd mysql
# Create user (- s /bin/false parameter specifies that the mysql user has only ownership and no login permission)
useradd -r -g mysql -s /bin/false mysql
# Add user groups and users to the mysql directory and its sub files
chown -R mysql:mysql ./
# Create MySQL profile
vi /etc/my.cnf
# Put the following
# -------------------------------------
[mysqld]
# Set 3306 port
port=3306
# Set mysql installation directory
basedir=/opt/apps/mysql8
# Set the storage directory of mysql database data
datadir=/opt/apps/mysql8/mysqldb
# Maximum connections allowed
max_connections=10000
# Number of connection failures allowed. This is to prevent someone from trying to attack the database system from the host
max_connect_errors=10
# The character set used by the server is UTF8 by default
character-set-server=utf8
# The default storage engine that will be used when creating new tables
default-storage-engine=INNODB
# The "mysql_native_password" plug-in authentication is used by default
default_authentication_plugin=mysql_native_password
[mysql]
# Set the default character set of mysql client
default-character-set=utf8
[client]
# Set the default port used by mysql client when connecting to the server
port=3306
default-character-set=utf8
# -------------------------------------
# Install mysql
cd /opt/apps/mysql8/bin
./mysqld --initialize --console

1.4 start mysql

cd /opt/apps//mysql8/support-files/
./mysql.server start

An error will be reported during the initial operation

We are not a professional dba. Here we will focus on violence. Just give mysql8 all permissions directly

chmod 777 /opt/apps/mysql8/
cd /opt/apps/mysql8/support-files
./mysql.server start


Start successful

1.5 log in to MySQL and change the password

cd /opt/apps/mysql8/bin
./mysql -uroot -pu3&k=d+yw+1y

An error will be reported

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I read many installation blogs and didn't mention it during installation. I have it every time I install it. It's really disgusting to me. A general solution here. First open the front my CNF configuration file, add a line skip grant tables under [mysqld], save it, and then execute / opt / apps / mysql8 / support files / MySQL Server restart restart the MySQL server, log in again, only enter the login name, and press enter when entering the password. If you can't do it once, you can log in secretly twice.
Change the login password,

use mysql

Note: version 8.0 does not allow password modification when skipping the policy skip grant tables.

First clear the root user password and delete my After adding skip grant tables to conf, you can change the password after accessing the database normally with an empty password.
Add: version 5.7 / 5.5 can directly change a new password at this time.

After clearing the password, enter exit; Exit mysql, delete skip grant tables in the configuration file, save it, restart mysql, enter the password again, and then you can modify the password.
When I re-enter mysql and enter the password change operation, another error will appear. My patience is really running out.

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

At this time, enter set password = 'a password that is complex enough and you remember';

Remember, don't enter a simple password, or you will report another error. This error is as follows

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

If you have to set a simple password like 123456, follow these steps
Execute the following two statements:

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

Then execute set password = 'a password that is complex enough and you remember';

1.6 configure to allow remote login

use mysql
update user set user.Host='%'where user.User='root';
flush privileges;
quit

1.7 turn off the firewall

In fact, 3306 port numbers can be opened in the firewall, but when learning nginx later, various port numbers are frequently used, so it's good to close them directly.

# View firewall status
systemctl status firewalld
# Temporarily turn off the firewall
systemctl stop firewalld
# Permanently turn off the firewall
systemctl disable firewalld
# service iptables restart 
systemctl restart firewalld.service

Using vscode to connect to mysql on Windows, the blogger I tested successfully.

1.8 configure MySQL path

vi /etc/profile, then add echo $PATH=$PATH:/opt/apps/mysql8/bin at the end, and finally execute source /etc/profile to log in to MySQL using MySQL in any directory.

1.9 setting mysql startup and self startup

First configure MySQL service, VI / etc / SYSTEMd / system / MySQL Service doesn't have this file, but this command will help us create MySQL in this directory service. Write the following in it

Description=mysql
[Service]
User=mysql
LimitNOFILE=100000
LimitNPROC=100000
ExecStart=/opt/apps/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf
[Install]
WantedBy=multi-user.target

Next, you can operate MySQL like the network service of the virtual machine

# Set startup and self startup
systemctl enable mysql
# View status after startup
systemctl status mysql

Restart the virtual machine, MySQL completes the password modification, startup and remote login. The resources have been given out. According to this operation, the possible problems have been told, and there are basically no problems.
I'm so tired. The uninstallation of MySQL will be updated later. Because this is not installed through yum, MySQL cannot be seen using rpm -qa|grep mysql. It is not easy to uninstall MySQL using rpm command.