Install the decompressed version of mysql5.7 under linux, and my girlfriend can install the database after reading this

Foreword:

Linux system centos7.2, mysql version 5.7, I have read many tutorials on the Internet, most of them failed, and the installation steps written by many people have many problems. I won’t explain them one by one here. This is a very high-quality installation tutorial. Pass it once to ensure that your girlfriend can see it successfully.

1. Preliminary preparation

1. Uninstall the old version of MySQL

Note that if it is a complete centos system, you don't need to install related dependencies, but you can execute the installation command if you don't know whether you have installed the related dependencies (it may take a long time). A centos7.2 system address is attached here, no need to install any dependencies, the system is ready to use
Address: https://pan.baidu.com/s/1SRiVqTJCyHoaE1cxjiL_Tg
Extraction code: gh26

查看rpm包
rpm -qa|grep mysql 若有可用rpm -e卸载

查找mysql残留包,有则删除,没有则忽略
find / -name mysql

安装相关依赖

yum -y install make gcc-c++ cmake bison-devel ncurses-devel numactl libaio

创建用户和用户组

groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql

2. Download and unzip the binary installation package

The download and installation package here may be slower, provide a network disk to download the version 5.7.31, the pro-test installation is available, and the other steps remain the same.
Address: https://pan.baidu.com/s/1JwCtrIL7dsbaZexoBHboUw
Extraction code: 4tub

cd /usr/local/
# wget下载或者本地下载后上传
wget https://downloads.mysql.com/archives/get/file/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# 解压安装包
tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# 解压后为了方便后面操作可把解压后文件名修改为mysql
mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql
# 更改文件夹所属
chown -R mysql.mysql /usr/local/mysql/

Three. Create mysql related directories and files

mkdir -p /data/mysql/{
    
    data,logs,tmp}
# 更改文件夹所属
chown -R mysql.mysql /data/mysql/

# 创建mysql配置文件my.cnf,已存在的话直接将内容覆盖就行
vi /etc/my.cnf
# 简单模板如下(可直接复制使用)[client]
port            = 3306
socket          = /data/mysql/tmp/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql        
datadir = /data/mysql/data  
port = 3306               

socket = /data/mysql/tmp/mysql.sock
pid-file  = /data/mysql/tmp/mysqld.pid
tmpdir = /data/mysql/tmp    
skip_name_resolve = 1
symbolic-links=0
max_connections = 2000
group_concat_max_len = 1024000
sql_mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names = 1
log_timestamps=SYSTEM
character-set-server = utf8
interactive_timeout = 1800  
wait_timeout = 1800
max_allowed_packet = 32M
binlog_cache_size = 4M
sort_buffer_size = 2M
read_buffer_size = 4M
join_buffer_size = 4M
tmp_table_size = 96M
max_heap_table_size = 96M
max_length_for_sort_data = 8096

#logs
server-id = 1003306
log-error = /data/mysql/logs/error.log
slow_query_log = 1
slow_query_log_file = /data/mysql/logs/slow.log
long_query_time = 3
log-bin = /data/mysql/logs/binlog
binlog_format = row
expire_logs_days = 15
log_bin_trust_function_creators = 1
relay-log = /data/mysql/logs/relay-bin
relay-log-recovery = 1  
relay_log_purge = 1  

#innodb  
innodb_file_per_table = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_flush_method = O_DIRECT
innodb_autoinc_lock_mode = 2
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_buffer_pool_size = 2G

Four. Configure mysql.server

cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql

# 修改目录位置
basedir=/usr/local/mysql
datadir=/data/mysql/data

 # 注册开机启动服务
chkconfig --add mysql
chkconfig --list

Five. Add environment variables

echo "PATH=$PATH:/usr/local/mysql/bin  " >> /etc/profile  
source /etc/profile

Six. Initialize mysql

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

# 临时密码保存在errlog中 
# 获取临时密码,该密码第一次登陆mysql时会被使用,注意密码可能是分号结尾,一起复制
more /data/mysql/logs/error.log |grep password

Seven. Start the mysql service and change the password

# 启动mysql服务
service mysql start
# 使用初始密码登录mysql服务 并修改密码,下面所示是将密码改为root
mysql -uroot -p
alter user 'root'@'localhost' identified by 'root';
flush privileges;

8. Navicat connection mysql problem 10038

The problem that is often reported is 10038, as shown in the figure below. There
Insert picture description here
are mainly three solutions collected on the Internet, as follows

1. The user table changes the host value of the root user

Log in to the mysql client in the system and view the user table information as follows

mysql -u root -p
# 登录成功后
use mysql;
select user,host from user;

The results are as follows:
Insert picture description here
If the host corresponding to root does not have% in the result found above, you need to change it (multiple roots, one of which corresponds to %), use the following command to change.

# 更改root的host值
update user set host = '%' where user = 'root';
# 刷新(改完一定要刷新)
flush privileges;

After these are done, you can try the connection test. If it still does not work, continue with the second method.

2. Check the bind-address value of the my.cnf configuration file

The my.cnf configuration file is generally stored in /etc/my.cnf, and it may be different. If you are not sure, you can use the find -name command to check the location of the file. The operation is as follows

# 全盘查找my.cnf(若是用户权限不足,可切换root查找)
find / -name my.cnf
cd /etc/mysql/my.cnf
vi my.cnf
# 将以下内容
# bind-address=127.0.0.1
更改为以下内容
bind-address=0.0.0.0

After the above operations, you can continue to test whether the connection can be successful. If this part is not changed, the remote connection cannot be made. Changing this part allows remote connection. If it still doesn't work, the nine achievements are a firewall problem.

3. Check the firewall status and turn off the firewall

Some port numbers are not allowed to pass through the firewall by default, and 3306 is a very common one, so when we use a remote connection, it is impossible to connect. We can directly use the command to view the firewall status, turn off the firewall and test it again. As follows:
Note:
Different systems have different commands. If the systems are inconsistent, you can query specific commands. Centos6 firewall is iptables, centos7 is firewalld, and the operation commands are also different.

# 查看防火墙放行的端口
firewall-cmd --list-ports
# centos7查看防火墙的状态
sudo systemctl status firewalld
# centos7关闭防火墙(临时更改,重启失效)
sudo systemctl stop firewalld
# centos7打开防火墙(临时更改,重启失效)
sudo systemctl start firewalld

If it has not been solved, it is recommended to use the 4 universal solution , which will definitely be solved. If it has been solved, the above command is only to temporarily turn off the firewall. This method will definitely not solve the problem forever. There are two permanent solutions, one is to permanently close the protective wall, the other is to allow the firewall to release port 3306, and it is recommended to use the firewall to release port 3306. The operation is as follows:

  1. centos7 permanently turn off the firewall

    # 关掉系统重启时重新启动防火墙的功能
    sudo systemctl disable firewalld
    # 关闭防火墙
    sudo systemctl stop firewalld
    # 重启后生效
    reboot
    

    Restart at this time, the firewall is closed, if you need to turn on the firewall, the command is as follows

    # 开启系统重启时重新启动防火墙的功能
    sudo systemctl enable firewalld
    # 开启防火墙
    sudo systemctl start firewalld
    # 重启后生效
    reboot
    
  2. Let the firewall allow port 3306.

    # 放行3306端口,然后一定要重启防火墙
    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    # 重启防火墙
    systemctl restart firewalld.service
    # 再次查看端口有没有放行成功,下面出现3306就表示成功了
    firewall-cmd --list-ports
    
    # 参数解释
    # –zone 用以标识该端口放行的范围
    # --add-port=3306/tcp 标识端口与通讯协议
    # --permanent 标识重启放行依然生效
    

4. The universal solution

The above three methods still do not work? Don't try, it may take less time to install a new one than to find a solution to the problem. Use the centos7.2 provided in the article, and install the package with mysql5.7.31 from the new installation (the article has a network disk link), and follow the above process to ensure it again However, if you are not connected during the remote connection, you can simply turn off the firewall. I have tested the entire process and there is no problem. I hope it will be helpful to those who are confused.

to sum up

After many attempts, I searched for a few tutorials that were all wrong, and finally got it done. The process is still a bit tortuous. In order to avoid making the same mistake next time, I summarized the article from installing this version to fixing the 10038 problem on the Internet. Many people provide tutorial articles, not to mention that the operating system version is actually meaningless. Even if the different versions of centos are different, they also take a warning. When operating, you must determine the problem according to the version, otherwise even if you find a high probability It is also unusable.

Support originality, this article refers to this article. https://blog.csdn.net/wanghao112956/article/details/90748883

Guess you like

Origin blog.csdn.net/m0_46897923/article/details/115110747