install mysql8.0 in centos system
- Environmental description
- start
-
- 1. Check whether there is MariaDB in centos7, please check the relationship between MariaDB and MySQL
- 2. If there is MariaDB, you need to uninstall all the mairadb queried in step 1, otherwise there will be problems with MySQL installation
- 3. Check whether MySQL has been installed on this machine
- 4. If you have installed MySQL, please confirm whether there is any data that needs to be backed up (if you have data that needs to be backed up, please refer to the relevant operations to back it up, otherwise you will not be responsible for data loss)
- 5. Uninstall MySQL
- 6. Download the mysql installation package for centos7 from the MySQL official website
- 7. Unzip the tar package
- The option here is to install all
- The installation sequence is as follows, otherwise there will be dependency problems
Environmental description
- Operating system: CentOS Linux release 7.9.2009 (Core)
- The MySQL version installed this time: 8.0.26
- Connection tools: xshell, xftp (or other connection/upload tools)
start
1. Check whether there is MariaDB in centos7, please check the relationship between MariaDB and MySQL
rpm -qa | grep mariadb
2. If there is MariaDB, you need to uninstall all the mairadb queried in step 1, otherwise there will be problems with MySQL installation
rpm -e --nodeps 软件名
3. Check whether MySQL has been installed on this machine
rpm -qa | grep -i mysql
4. If you have installed MySQL, please confirm whether there is any data that needs to be backed up (if you have data that needs to be backed up, please refer to the relevant operations to back it up, otherwise you will not be responsible for data loss)
If MySQL has not been installed, please skip to step 6
5. Uninstall MySQL
- Uninstall all the mysql installation packages queried in step 3
rpm -e --nodeps 软件名
- Find the mysql file and delete it
find / -name mysql
whereis mysql
- Delete all the mysql files queried by the find command and whereis command
rm -rf 查询到的mysql路径
- delete mysql configuration file
rm /etc/my.cnf
- Confirm whether to delete all mysql
rpm -qa | grep -i mysql
6. Download the mysql installation package for centos7 from the MySQL official website
- Query whether the server is of x86_64 architecture or arm architecture
uname -m
或者是
arch
# 我的服务器是x86_64的
- Here you can download it directly through the browser, and then upload it to the server to be installed through ftp
- Or copy the link of this tar package, and then download it through the wget command, the operation is as follows
wget 文件的网络地址
- For example, the address I downloaded here is
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar
- Either through
xftp工具
orwget命令
, transfer the MySQL tar package to a certain directory of centos (such as the home directory), here is the uploadedroot用户
home directory
7. Unzip the tar package
Before decompressing, it is recommended to create an empty directory first, because multiple rpm packages will be directly placed in the current directory after the tar package is decompressed. Because my tar package is in the root user's home directory, I created a mysql directory directly in this directory. This directory does not matter!
tar -xvf mysql的tar包全名 -C 解压到指定目录
# 说明:-C参数,后面跟的是目录,意思是将压缩包解压缩后存放到指定的目录下。
# 这里就指定到刚才创建的mysql目录下
8. Start to install MySQL
- rpm install command
rpm -ivh xxx.rpm
The option here is to install all
The installation sequence is as follows, otherwise there will be dependency problems
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-embedded-compat-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
rpm -ivh mysql-community-test-8.0.26-1.el7.x86_64.rpm
- When installing rpm above, the dynamic library of centos may be missing, etc. Here are several error situations recorded
情况1:
[root@VM-0-14-centos mysql]# rpm -ivh mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm
`warning: mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm`:
`Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY error: Failed
dependencies: libnuma.so.1()(64bit) is needed by
mysql-community-embedded-compat-8.0.26-1.el7.x86_64
libnuma.so.1(libnuma_1.1)(64bit) is needed by
mysql-community-embedded-compat-8.0.26-1.el7.x86_64
libnuma.so.1(libnuma_1.2)(64bit) is needed by
mysql-community-embedded-compat-8.0.26-1.el7.x86_64
Solution:
yum -y install numactl
情况2
[root@VM-0-14-centos mysql]# rpm -ivh mysql-community-devel-8.0.26-1.el7.x86_64.rpm
warning: mysql-community-devel-8.0.26-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
pkgconfig(openssl) is needed by mysql-community-devel-8.0.26-1.el7.x86_64
The solution is
yum install openssl-devel
情况3
[root@VM-0-14-centos mysql]# rpm -ivh mysql-community-test-8.0.26-1.el7.x86_64.rpm
`warning: mysql-community-test-8.0.26-1.el7.x86_64.rpm: Header V3` `DSA/SHA256` `Signature, key ID 5072e1f5: NOKEY`
error: Failed dependencies:
perl(Data::Dumper) is needed by mysql-community-test-8.0.26-1.el7.x86_64
The solution is
yum -y install autoconf
情况4
[root@VM-0-14-centos mysql]# rpm -ivh mysql-community-test-8.0.26-1.el7.x86_64.rpm
warning: mysql-community-test-8.0.26-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
perl(JSON) is needed by mysql-community-test-8.0.26-1.el7.x86_64
Solution
yum install perl-JSON.noarch -y
yum install perl.x86_64 perl-devel.x86_64 -y
情况5
[root@VM-0-14-centos mysql]# rpm -ivh mysql-community-test-8.0.26-1.el7.x86_64.rpm
warning: mysql-community-test-8.0.26-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
perl(Test::More) is needed by mysql-community-test-8.0.26-1.el7.x86_64
Solution:
Go to https://pkgs.org/download/perl(Test::More), open the drop-down box of centos7, find the corresponding rpm under CentOS x86_64, then open the rpm link, and find Binary Package in the corresponding part of Download , there is a corresponding rpm download link at the back, just download it and install it.
或者用命令安装即可:yum install perl-Test-Harness
9. Initialize the database
mysqld --initialize --console
10. Directory authorization, otherwise it may fail to start
chown -R mysql:mysql /var/lib/mysql/
11. Start mysql
systemctl start mysqld
- The corresponding restart and shutdown mysql commands are as follows
systemctl stop mysqld
systemctl restart mysqld
12. Query mysql status
systemctl status mysqld
13. Query the temporary password of mysql
cat /var/log/mysqld.log | grep password
14. Use a temporary password to log in to mysql
mysql -u root -p
- Note:
linux下输入密码是不会回显
(It’s not that the computer is broken!), just press Enter after inputting
- the password is entered correctly, and if you see the following information after pressing Enter, it means you have successfully entered mysql
15. Mysql login password
alter user ‘root’@‘localhost’ identified with mysql_native_password by ‘你的密码’ ;
Finally restart mysql
16. Mysql set remote connection
Note: This step is set according to actual needs
show databases ;
use mysql ;
View the host that can log in to mysql
select host, user from user;
host部分全部都是localhos
t, indicating that the user can only connect to the msyql service locally
- Modify the host value of the root user and refresh the mysql database
update user set user.host=’%'where user.user=‘root’;
flush privileges;
Use Navicat on my windows computer to test the connection to mysql on the server to see if it can be connected remotely
17. Other information
When the connection fails
- Does the firewall of centos7 open port 3306?
- Configuration of inbound and outbound rules for cloud servers