1. Check if MySQL is installed
1.1 Check to remove mysql
yum remove MySQL
1.2 Check if there is MySQL dependency
rpm -qa | grep mysql
1.3 If there is a dependent package, delete it
//Ordinary deletion mode rpm -e xxx(mysql_libs) // Force deletion mode, if the above command deletes, it prompts that there are dependencies on other files, you can use this command to forcefully delete them rpm -e --nodeps xxx(mysql_libs )
2. Check if mariadb exists
rpm -qa | grep mariadb
As in the above case, if there is mariadb, uninstall it
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
3. Upload the Mysql installation package and unzip it
3.1 Download the MySQL installation package, the official website address:
https://dev.mysql.com/downloads/mysql/
The database version installed in this article is Linux Generic MySQL Community Server 8.0.26
3.2 Decompression
Since the MySQL format I downloaded is:
mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
Unable to decompress with the following command
tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
You need to use the following command to convert it into ".tar format" and then decompress it with tar -xvf
xz -d mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
3.3 Move the decompressed package to a common installation location
Location "/usr/local/"
mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/
Supplement: Generally, the decompressed folder will simplify the name of the folder mysql-8.0.26
Enter the mysql-8.0.26 folder and create the mysqldb folder, which is used to store the library files of each database
cd mysql-8.0.26/ mkdir mysqldb
4. Install MySQL dependencies
yum install libaio
5. The mysql installation directory gives permissions
chmod -R 777 /usr/local/mysql-8.0.26/
6. Create mysql group and user
6.1 Create User Group
groupadd mysql
Create a user (the -s /bin/false parameter specifies that the mysql user only has ownership without login permissions)
useradd -r -g mysql -s /bin/false mysql
6.2 Adding users to groups
chown -R mysql:mysql ./
an examination
id mysql
7. Modify the mysql configuration file
vi /etc/my.cnf
Delete the configuration inside and add the following configuration
[mysqld] port=3306 # Set the installation directory of mysql basedir=/usr/local/mysql-8.0.26 # Set the storage directory of the data of the mysql database datadir=/usr/local/mysql-8.0.26/mysqldb # Allow the maximum Number of connections max_connections=10000 # Allow the number of connection failures. This is to prevent someone from trying to attack the database system from this host max_connect_errors=50 # The character set used by the server defaults to UTF8 character-set-server=utf8 # The default storage engine that will be used when creating new tables default-storage-engine=INNODB # Default use "mysql_native_password" plugin authentication default_authentication_plugin=mysql_native_password [mysql] # Set the default character set of the mysql client default-character-set=utf8 [client] # Set the default port used by the mysql client when connecting to the server port=3306 default- character-set=utf8
8. Install mysql
Enter the bin directory of the mysql installation directory
cd /usr/local/mysql-8.0.26/bin/
Install MySQL, and remember to initialize random passwords
./mysqld --initialize --console
Generated random password: AJCNuxm91p+y
AJCNuxm91p+y
9. Start the MySQL service
cd /usr/local/mysql-8.0.26/support-files/ ./mysql.server start
If the startup reports an error, Baidu will solve it by itself.
You can try to re-authorize the "mysql-8.0.26" installation directory and restart the service
chmod -R 777 /usr/local/mysql-8.0.26 ./mysql.server start
10. Add mysql to the system process
enter bin
cd /usr/local/mysql-8.0.26/bin/ cp /usr/local/mysql-8.0.26/support-files/mysql.server /etc/init.d/mysqld
At this point, you can operate mysql through the service process
11. Set MySQL to start automatically
enter bin
cd /usr/local/mysql-8.0.26/bin/ systemctl enable mysqld
At this point, it is set to start automatically.
12. Modify MySQL password
Before modifying, open the MySQL service and check whether the MySQL service is enabled. If an error occurs during the opening process
Starting MySQL.The server quit without updating PID file (/[FAILED]l/mysql-8.0.26/mysqldb/iZuf69hnxir266m4aqb8teZ.pid).
Because the cache file in the previously started service cannot be updated
Processing method Delete the corresponding pid cache file
chown -R mysql /usr/local/mysql-8.0.26/ chown -R 'User created when installing MySQL' '/usr/local/installed directory'
enter bin
cd /usr/local/mysql-8.0.26/bin/ ./mysql -u root -p
Enter a temporary password
change Password
mysql> alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
13. Set up remote login
operate in the database
mysql> use mysql mysql> update user set user.Host='%'where user.User='root'; mysql> flush privileges; mysql> quit
14. Restart the service test
systemctl restart mysql service mysql restart
15. Check if it has been started
systemctl status mysql