Centos7 installs MySQL5.7.30


CentOS 7 is one of the most popular Linux operating systems, and MySQL is one of the most commonly used relational databases. In this article, we will provide a simple step-by-step guide to help you successfully install MySQL version 5.7.30.

1. Environment preparation

1.1 uninstall mariadb

The linux system will automatically carry a database, we need to uninstall it

You can view mariadb through the following code

rpm -qa | grep mariadb

uninstall mariadb

yum remove mariadb-libs-5.5.68-1.el7.x86_64 -y

Check again to see if the uninstallation was successful

rpm -qa | grep mariadb

insert image description here

insert image description here

1.2 Download MySQL 5.7.30

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

insert image description here

1.3 Install MySQL dependencies

Before installing MySQL, you need to make sure the following dependencies are installed in your system:

libaio library
numactl library
You can use the following commands to install these libraries:

sudo yum install libaio  
sudo yum install numactl

1.4 Create directory

Data path: /data/mysql/data
Communication path: /tmp/mysql Used to generate sock files in this directory when the database starts

1.5 Create users and user groups

groupadd mysql   #新建一个msyql组
useradd -r -g mysql mysql # 新建Mysql用户

1.6 Modify Mysql user permissions

chown -R mysql:mysql /usr/local/mysql/
chmod -R 755 /usr/local/mysql
chown -R mysql:mysql /data/mysql

2. Install MySQL

If you can't find the compressed package, you can search

find / -name mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

insert image description here

2.1 Decompression

tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

insert image description here

2.2 Modify the decompression directory name

insert image description here

2.3 Initialization

./mysqld --initialize --user=mysql --datadir=/data/mysql/data --basedir=/usr/local/mysql

insert image description here

2.4 Add my.cnf

[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
datadir = /data/mysql/data


abnormal

Sock file not found

insert image description here

lsof -c mysql|grep sock$			#寻找mysql.sock是否存在
find / -name mysql.sock				#寻找mysql.sock位置

insert image description here
The location of the configuration file here is different from that of mysql.sock.
Change /tmp/mysql/mysql.sock to /tmp/mysql.sock

2.5 Start the MySQL service

After the installation is complete, you need to start the MySQL service. You can start MySQL with the following command:

  sudo systemctl start mysqld.service

You can also use the following commands to enable the MySQL service and start it automatically at system boot:

sudo systemctl enable mysqld.service

2.5.1 Establish soft connection

If the above method cannot be used, the following command can be used

ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

2.5.2 Start

The command is as follows:

/etc/init.d/mysql start

2.6 Set MySQL root account password

After the MySQL installation is complete, you need to set a password for the root account.

set password for root@localhost = password('123456');

Step 6: Login to MySQL

Finally, you can log in to MySQL as root with the following command:

mysql -u root -p

Enter the set password to log in successfully.
login successful
insert image description here

2.7 Open remote connection

use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;    //刷新权限

insert image description here

3. MySQL boots automatically

# 添加mysqld服务、
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# 添加可执行权限
chmod +x /etc/init.d/mysqld
# 添加开机自启服务
chkconfig --add mysqld
# 查看开机自启列表
chkconfig --list

3.1 Results

insert image description here
If it is different from the picture above, please change 345 to on, the command is as follows:

chkconfig --level 345 mysqld on

in conclusion

Installing version 5.7.30 of MySQL is very easy, just follow the above steps.

Guess you like

Origin blog.csdn.net/dwh19992018/article/details/129993937