How to install mysql5.7.21 on centos in Linux,
Preparations:
Environment: linux
System: centos6.4-x86-x64
Installation Tool: mysql-5.7.21-x86-64
Software Download:
Mysql
Or: mysql-5.7.21 Binary Package.
Or use wget for download in linux:
Wget-xp
Preparations:
1. Install the wget plug-in:
Command: sudo yum-y install wget
2. Centos6.4 replace yum with Alibaba Cloud
1. Directory of the Source:/etc/yum. repos. d/
Backup source file:
Cp-rp/etc/yum. repos. d/CentOS-Base.repo/etc/yum. repos. d/CentOS-Base.repo.backup
2. download the new CentOS-Base.repo to/etc/yum. repos. d/
CentOS 6
Wget-O/etc/yum. repos. d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
Wget-O/etc/yum. repos. d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
3. yum clean all
4. yum makecache
The source installation is complete.
There are many ways to install mysql in linux. Here I install mysql in binary mode. My personal reason is that the installation directory is configured according to your preferences.
Check whether the mysql database is installed on the operating system.
Rpm-qa | grep mysql
Show version:
Mysql57-community-release-el7-8.noarch
Delete an existing version
Rpm-e -- nodeps mysql57-community-release-el7-8.noarch
Check whether the deletion is successful
Rpm-qa | grep mysql
View the mysql database version on yum
Yum list | grep mysql
If you have installed mysql on your system. For example, if you want to install mysql 5.6, perform the following operations:
# Check mysql
Find/-name mysql
# Delete an installed mysql instance
Find/-name "* mysql *" | xargs rm-rf
Note: After uninstallation,/etc/my. cnf is not deleted and must be manually deleted.
Rm-rf/etc/my. cnf
Upload the downloaded installation package "mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz" to the/opt directory using xftp, decompress it, rename it, move the mysql directory
Tar-zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
Mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql-5.7.21
Mkdir mysql
Mv/opt/mysql-5.7.21/opt/mysql
The following is my local mysql5.7.21 directory (/opt/mysql/mysq-5.7.21)
Create a data directory in this directory for database storage.
Cd/opt/mysql/mysql-5.7.21
# Create a data directory and a database storage directory
Mkdir data
Ls-l
As follows:
Create a mysql user group and a mysql user
# Check whether there are any mysql groups
Cat/etc/group | grep mysql
Check whether there are any mysql users
Cat/etc/passwd | grep mysql
If no, create a mysql group.
# Create a mysql user group
Groupadd mysql
# Create a mysql user and add it to the mysql user group (// useradd-r parameter indicates that the mysql user is a system user and cannot be used to log on to the system; the first mysql user is a user group, the second mysql is the user)
Useradd-r-g mysql
# Check whether the user group is successfully created
Groups mysql
Set mysql directory access permission, user group
# Grant the mysql directory access permission to the myql user
Chown-R mysql/opt/mysql/mysql-5.7.21/
# The user group for changing the mysql directory belongs to the mysql Group
Chgrp-R mysql/opt/mysql/mysql-5.7.21/
# View all directories and folders under the mysql directory.
Cd/opt/mysql/mysql-5.7.21
Ls-l
The effect is as follows: Users and user groups are changed from root to mysql users and user groups.
Create the following file and set the access permission for mysql Configuration
Create a file/tmp/mysql. sock
Assign permissions:
Chown-R mysql: mysql/tmp/mysql. sock
Chmod 755/opt/mysql-5.7.21/tmp/mysql. sock
Create a file:/opt/mall/mysql/log/mysqld. log
Assign permissions:
Chown-R mysql: mysql/opt/mall/mysql/log/mysqld. log
Chmod 755/opt/mall/mysql/log/mysqld. log
Create a file:/opt/mall/mysql/run/mysqld. pid
Assign permissions:
Chown-R mysql: mysql/opt/mall/mysql/run/mysqld. pid
Chmod 755/opt/mall/mysql/run/mysqld. pid
Note:
Chmod: used to change the access permissions of files or directories. It is generally used to control the access permissions of files or directories.
Chmod 755/tmp/mysql. sock
Chown: Change the files and directories in a directory to a user group.
Chgrp: Change files and directories in a directory to a group.
-R processes the specified directory and all files in its subdirectories.
Chown-R mysql. Change the owner of the files and directories in the current directory to a mysql user.
Chgrp-R mysql. Change the file and directory group in the current directory to the mysql group.
Install and initialize a database
Cd/opt/mysql/mysql-5.7.21
Bin/mysqld -- initialize -- user = mysql -- basedir =/opt/mysql/mysql-5.7.21 -- datadir =/opt/mysql/mysql-5.7.21/data
Report after execution:
Error message:
Error while loading shared libraries: libnuma. so.1: cannot open shared object file: No such file or directory
Solution:
Cause:
Libnuma. so.1 is installed in yum, but 32 is installed by default, while 64-bit is required in db2.
1. If libnuma. so.1 has been installed, yum remove libnuma. so.1 first
2. install the dependency package yum-y install numactl. x86_64
Note:
SLES 11: From MySQL 5.7.19, the general tar package format for Linux is EL6 rather than EL5, so that the MySQL client bin/mysql needs libtinfo. so.5
After the dependency package is installed, continue to run as follows. Note that the last line is the initial mysql password.
Configure SSL parameters
Cd/opt/mysql/mysql-5.7.21
Bin/mysql_ssl_rsa_setup -- datadir =/opt/mysql/mysql-5.7.21/data
Since the mysql-5.7.21 version my. cnf is not under/support-files, we create the my. cnf file and copy the following content:
Touch/etc/my. cnf
Vim/etc/my. cnf
[Mysqld]
Character_set_server = utf8
Init_connect = 'set NAMES utf8'
Basedir =/opt/mysql/mysql-5.7.21
Datadir =/opt/mysql/mysql-5.7.21/data
Port = 3306
Socket =/tmp/mysql. sock
Log-error =/opt/mall/mysql/log/mysqld. log
Pid-file =/opt/mall/mysql/run/mysqld. pid
# The table name is case insensitive.
Lower_case_table_names = 1
SQL _mode = STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION
Max_connections = 5000
Configure Automatic mysql startup
Cd/opt/mysql/mysql-5.7.21
Cp support-files/mysql. server/etc/init. d/mysql
# Because mysql is installed in the/opt/mysql/mysql-5.7.21, You need to modify the mysql installation path of the/etc/init. d/mysql File
Vim/etc/init. d/mysql
Basedir =/opt/mysql/mysql-5.7.21
Datadir =/opt/mysql/5.7.21/data
# Add the mysql service control script execution permission
Chmod + x/etc/init. d/mysql
# Use the chkconfig command to add the mysqld service to the self-starting service item
Chkconfig -- add mysql
Check whether the configuration is successfully added.
Chkconfig -- list mysql
Start mysql
Cd/opt/mysql/mysql-5.7.21
Bin/mysqld_safe -- user = mysql &
Run the service mysql command to start/stop and view the service
# Viewing mysql status
/Etc/init. d/mysql status or service mysql status
# Start mysql
/Etc/init. d/mysql start or service mysql start
# Stopping mysql
/Etc/init. d/mysql stop or service mysql stop
# Restarting mysql
/Etc/init. d/mysql restart or service mysql restart
View mysql service description started successfully
Ps-ef | grep mysql
Add the system path and add the following code at the end of the file:
Vim/etc/profile
Export PATH =/opt/mysql/mysql-5.7.21/bin: $ PATH
Or
Echo "export PATH = $ PATH:/opt/mysql/mysql-5.7.21/bin">/etc/profile
Set the environment variable to take effect immediately
Source/etc/profile
Put the mysql client in the default path:
Ln-s/opt/mysql/mysql-5.7.21/bin/mysql/usr/local/bin/mysql
Note: We recommend that you use soft links instead of directly copying package files to facilitate system installation of multiple versions of mysql.
A soft link is used to create a shortcut for the mysql client.
Modify mysql password
Cd/opt/mysql/mysql-5.7.21/bin
./Mysql-u root-p
Temporary password generated above the password: 34 = y7 &/MsmJe
Mysql> set password = password ("newpassword ");
Or mysql-u root-p # log on to mysql
# View the mysql version
Mysql> select version ();
# Viewing Databases
Mysql> show databases;
Temporary password generated above the password: 34 = y7 &/MsmJe
Set remote Logon (Be sure to enter the mysql status)
[Root @ admin mysql-5.7.21] # mysql-u root-p
Mysql> use mysql;
Mysql> update user set host = '%' where user = 'root ';
Grant all privileges on *. * TO 'myuser' @ '% 'identified BY 'mypwd' with grant option;
Mysql> flush privileges;
Mysql> exit;
# Restarting mysql
Service mysql restart;
Test whether the remote connection is normal:
This is because the linux firewall is not disabled and port 3306 is not enabled.
# Check whether port 3306 is enabled
Netstat-an | grep 3306
# Directly disable the Firewall
Chkconfig iptables off
# Do not close the firewall, only open port 3306
Vim/etc/sysconfig/iptables
-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT
-A input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT
Note:
Centos6.0 firewall operations
View the Firewall status: service iptables status
Disable firewall: chkconfig iptables off # disable Firewall Service
Enable Firewall: chkconfig iptables on
Restart firewall: service iptables restart
Do not close the firewall, only open port 3306
Sudo iptables-I INPUT-p tcp-m tcp -- dport 80-j ACCEPT
Sudo service iptables save
Centos7.0 firewall operation (firewall is used as the firewall by default. If the firewall is not changed to iptables, run the following command to view and disable the firewall)
View the firewall Status: firewall-cmd -- state
Disable firewall: systemctl stop firewalld. service
Systemctl stop firewalld. service # stop firewall
Systemctl disable firewalld. service # disable firewall startup
Do not close the firewall, only open port 3306
Firewall-cmd -- zone = public -- add-port = 3306/tcp -- permanent
Firewall-cmd -- reload
Refer:
Https://linux.cn/article-4243-1.html
Test whether the remote connection is normal
Windows + R -- cmd
Mysql-h 192.168.174.128-u root-p
Enter Password