Install MySql5.7.18 under Linux

Table of contents

1. Installation in the form of rmp

1. Upload the offline installation package mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar

 2. Create mysql user

3. Install mysql-community-common-5.7.18-1.el7.x86_64.rpm

4. Install mysql-community-libs-5.7.18-1.el7.x86_64.rpm

5. Install mysql-community-client-5.7.18-1.el7.x86_64.rpm

6. Install mysql-community-server-5.7.18-1.el7.x86_64.rpm

2. Installation in the form of binary files (glibc)

1. Upload the offline installation package mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

2. Create mysql user

3. Unzip

4. Initialize the database

5. Specify the data storage location and modify the configuration file

6. Start the database first, and let it create mysql.sock and mysqld.pid files

7. Set the boot to start

8. Configure environment variables

3. Start, stop, password

1. Start mysql

2. View mysql status

3. View the default login password

4. Login

5. Change password

6. Authorize remote connection

7. Modify password security level

8. Open the port


1. Installation in the form of rmp

You can specify the data file location and log location, but you cannot specify the installation location.

1. Upload the offline installation package mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar

Upload to /opt, decompress:

tar -xvf mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar

 2. Create mysql user

Since the mysql database itself needs to use a user named mysql.

groupadd mysql              #创建名为mysql的分组
useradd mysql               #创建名为mysql的用户
passwd mysql                #给mysql用户设置密码
gpasswd -a mysql mysql      #将mysql用户加入到mysql分组中

3. Install mysql-community-common-5.7.18-1.el7.x86_64.rpm

rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm


If the error shown above occurs, execute:

yum -y remove mariadb-libs

Install again: 

4. Install mysql-community-libs-5.7.18-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm

5. Install mysql-community-client-5.7.18-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm

6. Install mysql-community-server-5.7.18-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm

If it prompts that libaio.so.1 is required, and when installing libaio.so.1, it prompts that it has been installed, consider replacing the old version libaio.so.1 
to check the installed libaio version: rpm -qa | grep -i libaio
Uninstall: yum remove libaio -0.3.109-13.el7.i686
upload libaio-0.3.107-10.el6.x86_64.rpm offline package
install libaio: rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm
install mysql-community again -server-5.7.18-1.el7.x86_64.rpm

7. Specify the data storage location and modify the configuration file:

mkdir /data/mysql
chmod 777 /data/mysql
vi /etc/my.cnf

Configuration file content:

[mysqld]
datadir=/data/mysql/data            #由mysql自动创建,属主为mysql
socket=/data/mysql/data/mysql.sock
[client]
default-character-set=utf8
socket=/data/mysql/data/mysql.sock
[mysql]
default-character-set=utf8
socket=/data/mysql/data/mysql.sock

2. Installation in the form of binary files (glibc)

You can specify the installation location, data file location, and log location.

1. Upload the offline installation package mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

Upload to /opt

chmod 777 /opt

2. Create mysql user

Since the mysql database itself needs to use a user named mysql.

groupadd mysql              #创建名为mysql的分组
useradd mysql               #创建名为mysql的用户
passwd mysql                #给mysql用户设置密码
gpasswd -a mysql mysql      #将mysql用户加入到mysql分组中

3. Unzip

su mysql
tar -zxvf /opt/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /opt
mv /opt/mysql-5.7.18-linux-glibc2.5-x86_64 /opt/mysql
mkdir /opt/mysql/data
mkdir /opt/mysql/logs
exit

4. Initialize the database

su mysql
/opt/mysql/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --log-error=/opt/mysql/logs/mysqld.log --explicit_defaults_for_timestamp
exit

5. Specify the data storage location and modify the configuration file

The location of /etc/my.cnf is the general configuration of mysql. If you want to use it alone, you must create it under the mysql installation path.

vi /etc/my.cnf    #通用配置
#vi /opt/mysql/my.cnf    #独立配置,不建议,会出现.sock文件问题,目前未找到解决办法

Configuration file content:

[mysqld]
datadir=/opt/mysql/data
socket=/opt/mysql/data/mysql.sock
user=mysql
symbolic-links=0

[mysqld_safe]
log-error=/opt/mysql/logs/mysqld.log
pid-file=/opt/mysql/data/mysqld.pid

[client]
default-character-set=utf8
socket=/opt/mysql/data/mysql.sock

[mysql]
default-character-set=utf8
socket=/opt/mysql/data/mysql.sock

6. Start the database first, and let it create mysql.sock and mysqld.pid files

su mysql
/opt/mysql/bin/mysqld_safe

Then kill the mysql process.
It may get stuck when executing mysqld_safe, don't worry about it, as long as the /opt/mysql/data/mysql.sock file is created normally. Anyway, it is necessary to kill the process.

exit

7. Set the boot to start

cp /opt/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
vim /etc/rc.d/init.d/mysqld

Change

basedir=/opt/mysql
datadir=/opt/mysql/data

 chmod +x /etc/rc.d/init.d/mysqld

Add the mysqld service to the system service and check whether it takes effect

chkconfig --add mysqld
chkconfig --list mysqld

8. Configure environment variables

If you want to log in to the mysql database from the local command line, you may need to configure environment variables:

vim /etc/profile

addition:

#mysql环境变量
PATH=$PATH:/opt/mysql/bin
export PATH

make the environment variable take effect

source /etc/profile


3. Start, stop, password

1. Start mysql

systemctl start mysqld

2. View mysql status

systemctl status mysqld

3. View the default login password

cat 日志路径 | grep password

4. Login

mysql -uroot -p

If you are prompted that the mysql.sock file cannot be found, you can specify the file location:

mysql --socket=/opt/mysql/data/mysql.sock -uroot -p

Then enter the password as prompted:

 5. Change password

5.1 Install in rmp form, with security level, the default security level must be uppercase + lowercase + numbers + special symbols

mysql> SET PASSWORD = PASSWORD('HTht123456@');

5.2 Binary file (glibc) installation, no security level, can be set casually

mysql> SET PASSWORD = PASSWORD('123456');

6. Authorize remote connection

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'HTht123456@' WITH GRANT OPTION;

Note: You must re-authorize after changing the password.

7. Modify password security level

To view existing password policies:

mysql> SHOW VARIABLES LIKE 'validate_password%';

Parameter explanation:
1).validate_password_dictionary_file specifies the file path for password validation;
2).validate_password_length the minimum length of the password
3).validate_password_mixed_case_count the number of lowercase letters and uppercase letters that the password must contain at least;
4).validate_password_number_count the number that the password must contain at least Number
5).validate_password_policy Password strength check level, the corresponding level is: 0/LOW, 1/MEDIUM, 2/STRONG, the default is 1
6).validate_password_special_char_count The number of special characters that the password must contain at least

Password strength check level:
0/LOW: only check the length;
1/MEDIUM: check the length, numbers, case, special characters;
2/STRONG: check the length, numbers, case, special characters dictionary file.

Can be set to check only 6-digit password length:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=6;

At this point, you can set a simple account password as a test account.

8. Open the port

CentOS 7 and below versions open the port number:

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT     #开放3306端口号
/etc/rc.d/init.d/iptables save                            #让配置文件生效

For CentOS 7 and above, turn off the firewall:

systemctl status firewalld.service    #查看防火墙状态
systemctl stop firewalld.service      #临时关闭防火墙
systemctl disable firewalld.service   #永久关闭防火墙

Guess you like

Origin blog.csdn.net/qq_33427869/article/details/125848436