1. Download the installation package
Mysql official address: MySQL https://www.mysql.com/
Open the official website address
Click on DOWNLOADS
Enter the DOWNLOADS page
Select MySQL Community (GPL) Downloads » Enter
Here select Download Archvies to enter
Then choose MySQL Community Server to enter, choose according to your server configuration, my server is CentOS 7, so choose Red Hat Enterprise Linux / Oracle Linux for Operating System, choose Red Hat Enterprise Linux 7 / Oracle Linux 7 for OS Version (x86,64-bit ).
Select the first one and click Download to download
2. Installation steps
Connect to the Linux server, create a mysql folder to put the installation package
Then upload the previously downloaded MySQL installation package under Linux, and use the rz command (if there are garbled characters, use the rz –be command)
#Create a mysql-8.0.31 folder under the current directory ( mysql )
mkdir mysql-8.0.31
# Unzip the installation package to this directory
tar -xvf mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar -C mysql-8.0.31
You can see that the decompressed files are all rpm files, so you need to use the instructions related to the rpm package explorer to install these rpm installation packages
Download the openssl-devel plug-in before installing and executing the rpm installation package, because some rpm installations in mysql depend on this plug-in.
yum install openssl-devel
The follow-up content comes from Linux-Installing MySQL (Detailed Tutorial)
After installing the plugin, 依次
execute the following command to install these rpm packages
rpm -ivh mysql-community-common-8.0.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.26-1.el7.x86_64.rpm
Note: When installing the rpm package, it prompts that the dependency detection failed. Please refer to the possible problems at the end of the file for solutions.
After MySQL is installed in Linux, the system will automatically register a service, the service name is mysqld, so you can operate MySQL through the following commands:
Start the MySQL service: systemctl start mysqld
Restart the MySQL service: systemctl restart mysqld
Close the MySQL service: systemctl stop mysqld
Start the MySQL service first here
Rpm install MySQL will automatically generate a random password, you can /var/log/mysqld.log
find the password in this file
cat /var/log/mysqld.log
A temporay password is generated for root
@localhost: ****密码****
, the temporary password generated by the MySQL I installed here is: JAgc=S-:4fGC
, the account number is root
, and you can connect to MySQL after you have the account number and password.
# Connect to MySQL
mysql -u root -p
At this point, the installation of MySQL on Linux is basically over.
3. Uninstall
Before uninstalling MySQL, you need to stop MySQL first
Order:systemctl stop mysqld
After stopping MySQL, query the MySQL installation file:rpm -qa | grep -i mysql
Uninstall all MySQL installation packages from the above query
rpm -e mysql-community-client-plugins-8.0.26-1.el7.x86_64 --nodeps
rpm -e mysql-community-server-8.0.26-1.el7.x86_64 --nodeps
rpm -e mysql-community-common-8.0.26-1.el7.x86_64 --nodeps
rpm -e mysql-community-libs-8.0.26-1.el7.x86_64 --nodeps
rpm -e mysql-community-client-8.0.26-1.el7.x86_64 --nodeps
rpm -e mysql-community-libs-compat-8.0.26-1.el7.x86_64 --nodeps
Delete the MySQL data storage directory
rm -rf /var/lib/mysql/
Delete MySQL configuration file backup
rm -rf /etc/my.cnf.rpmsave
4. Common settings
(1) Modify root user password
If you think the password automatically generated by MySQL is too difficult to remember, you can change the password after connecting to MySQL
ALTER USER 'root'@'localhost' IDENTIFIED BY 'mike.8080';
Here you may be prompted Your password does not satisfy the current policy requirements, which means that your password does not meet the current policy requirements, you can either set your password to be more complicated, or reduce the password verification rules.
When installing MySQL on Linux, a plug-in for verifying passwords will be automatically installed. The default password checking policy requires that passwords must contain: uppercase and lowercase letters, numbers and special symbols, and the length should not be less than 8 characters. Whether the new password complies with the current policy when changing the password, if not, it will prompt ERROR
The password verification rules can be found on the official website, search in the document: validate_password
Therefore, you can set the number of restricted passwords to be smaller, and the complexity type to be lower.
# Adjust password complexity check simple type
set global validate_password.policy = 0;
# Set the minimum number of passwords to 4 digits
set global validate_password.length = 4;
You can set a simpler password.
(2) Create users and assign permissions
The default root user can only access the current node localhost, and cannot access remotely. We also need to create a new account for remote access
Grammar format:CREATE USER <用户名> [ IDENTIFIED ] BY [ PASSWORD ] <口令>
# mysql 8.0 以下
create user 'mike'@'%' IDENTIFIED BY 'mike8080';
# mysql 8.0
create user 'mike'@'%' IDENTIFIED WITH mysql_native_password BY 'mike8080';
Note: The default password authentication of mysql8.0 is no longer password. So when creating a user, create user 'username'@'%' identified by 'password'; the client cannot connect to the service, so you need to add WITH mysql_native_password when creating a user
After creating the user, you need to assign permissions to the user. Here I mike
assign all permissions to this user.
grant all on *.* to 'mike'@'%';
If you want to assign permissions more finely, please refer to the blog: mysql assigns permissions to users
5. May encounter problems
(1) Prompt when starting MySQL Failed to start mysqld.service: Unit not found.
If you see this prompt, it means that the mysql installation has failed. My suggestion is to uninstall and reinstall.
(2) Prompt when installing the rpm package 依赖检测失败
Solution:卸载mariadb-libs
rpm -e mariadb-libs --nodeps
Then reinstall the rpm package that failed
(3) There is an error in the remote connection. If turning off the firewall cannot solve the problem, see the article Navicat connection database appears is not allowed to connect to this MySQL server error reporting