Article directory
-
- 1. Uninstall unnecessary environments
- 2. Check the system installation package
- 3. Get the official yum source of mysql
- 4. Install the mysql yum source and compare the yum sources before and after
- 5. Install mysql service
- 6. View configuration files and data storage locations
- 7. Start services and view startup services
- 8.Login
- 9.Configure my.cnf
1. Uninstall unnecessary environments
First check if mariadb exists
ps ajx |grep mariadb
If so, stop the mariadb service.
systemctl stop mariadb.service
2. Check the system installation package
rpm -qa | grep mysql
Delete these installation packages
rpm -qa | grep mysql | xargs yum -y remove
After deletion, we will check it again, then check the configuration file and delete it if it is found.
ls /etc/my.cnf
In addition, we can also use the following command to view the previous MySQL data. This does not need to be deleted.
ls /var/lib/mysql
3. Get the official yum source of mysql
Get mysql official yum source:mysql official yum source
You can see various versions as follows:
It is best to install the same mysql version as your own system, otherwise there may be software compatibility issues
Check your system version
cat /etc/redhat-release
Then find the resources that are consistent with your own version on the official website, download them to your local computer, and then upload them to your Linux server (create a separate directory and download the resources to this directory)
4. Install the mysql yum source and compare the yum sources before and after
View our local yum source
We can use the following command to install the yum source
rpm -ivh 下载的文件名
The following is the yum source after installation
Let's see if it can work normally
yum list | grep mysql
5. Install mysql service
Now we can install mysql
yum install -y mysql-commuinty-server
If you encounter the problem of key expiration
Failing package is: mysql-community-client-5.7.39-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
We use the following instructions in the command line to solve the problem:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
6. View configuration files and data storage locations
After installation, we will check the configuration file and data storage location and verify that the installation is successful.
ls /etc/my.cnf
which mysql
which mysqld
7. Start services and view startup services
Then we can start the service
systemctl start mysqld.service
View startup services
ps axj | grep mysql
We can use the following command to view the service port number of mysql
netstat -nltp
8.Login
Here we provide 3 login methods
method one
We use the following command to obtain the temporary root password
sudo grep 'temporary password' /var/log/mysqld.log
//最后的为临时密码
2021-04-12T03:23:46.153263Z 1 [Note] A temporary password is generated for
root@localhost: yLMalT:v+5l*
Then log in using the temporary password
mysql -uroot -p
Method Two
If the latest mysql you installed does not have a so-called temporary password, and root has no password by default, try logging in directly with the client.
Method three
Open mysql configuration file
vim /etc/my.cnf
Configure in the last column of [mysqld] (I don’t know what it is, so I put it at the end of the configuration file). Add: skip-grant-tables option, and save and exit.
Then restart the mysql service
systemctl restart mysqld
You can also pause the service first and then start the service
systemctl stop mysqld
systemctl start mysqld
Then we can log in
After logging in, we can use the following command to change the password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 密码
9.Configure my.cnf
Configure my.conf, mainly the encoding format of the database client and server
We can insert the following three lines in the etc/my.cnf file, which are port, encoding format and character set verification rules.
port=3306
character-set-server=utf8
default-storage-engine=innodb
Finally, we can set up startup. This does not need to be set.
systemctl enable mysqld
systemctl daemon-reload