MySql installation detailed tutorial and common errors

1. MySql installation file download

Official website download address: https://dev.mysql.com/downloads/mysql/5.7.html#downloads

mysql operating system and version selection

Note: You can choose different operating systems and versions

Windows version
Windows select the corresponding version and 64-bit operating system, click Next according to the prompts, after the installation is complete, add path to the environment variable as the installation path of MySql. At the same time, you can set the MySql service in the service registry to start at boot;
Note: When installing a higher version of MySql, select the lower version authorization method for password authorization; sha256 login will be more complicated

This page mainly talks about installing MySql under the linux operating system

2. Install MySql under linux

1. Download the Mysql compressed package

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

problem:

1.1 If the wget name does not exist, you can install wget first and execute the yum install wget command;
1.2 if yum mirrors 404, consider changing to a higher version to download the centos7 version, or you can download the compressed package and upload it to the linux server. I upload and download for general use rz (upload resources from windows to linux server) and sz (send from linux server to windows machine) commands. If you cannot execute the rz sz command, you can install yum install lrzsz

MySql tar.gz under linux

2. Unzip

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

mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql

3. Configure MySql

// 添加用户组用户
groupadd mysql
useradd -r -g mysql mysql

// 创建MySql数据文件夹
mkdir -p  /data/mysql             
chown mysql:mysql -R /data/mysql 
vim /etc/my.cnf
## my.cnf配置文件
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
character_set_server=utf8mb4

//初始化数据库
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
// 查看密码
cat /data/mysql/mysql.err
// 设置mysql 快捷命令
ln -s  /usr/local/mysql/bin/mysql    /usr/bin
// 将mysql.server 加入service
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
// 启动Mysql
service mysql start

// 修改密码
mysql -u root -p 默认密码

SET PASSWORD = PASSWORD('root.404');

ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;

Problem:
3.1 Navicat for MySQL 1130 error, Navicat connection error

use mysql                                            
update user set host = '%' where user = 'root';      
FLUSH PRIVILEGES;