preface

This article introduces the basic installation and configuration of MySQL, and describes how to install MySQL on different platforms (Windows, Linux, and MacOS). At the same time, the MySQL version file used in this article can be found on the web disk link at the end of the article or downloaded by yourself through the official website link.

Windows

On Windows, I installed mysql-5.7.34-Winx64 and installed it as a compressed package (see the resource link for the compressed package at the end of the article). First, I decompressed the compressed package to the specified folder (you can choose other locations here. System disk is generally not recommended, and permission problems may occur. Since I am using virtual machine environment test, so also arbitrary) :

Create a new my.ini file in this directory with the following contents:

[client]
default-character-set=utf8

[mysqld]
port = 3306
Set mysql installation directory
basedir=C:\Program Files\mysql-5.7.34-winx64
Mysql > select * from 'mysql'
datadir=C:\Program Files\mysql-5.7.34-winx64\data
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
Copy the code

MYSQL_HOME = MYSQL_HOME = MYSQL_HOME = MYSQL_HOME = MYSQL_HOME = MYSQL_HOME

Add environment variables to Path and close all configuration Windows:

Then use win + S to search for CMD and select open as administrator:

If the computer is new and many environments have not been configured, the following error may occur:

This is caused by the lack of VCREdist. You can choose the file in the link of the web disk or refer to the download address on the official website at the end of the article. After downloading, you only need to install it as prompted, and then run the following command in CMD:

mysqld -install
mysqld --initialize-insecure --user=mysql
net start mysql
Copy the code

MySQL > install MySQL > install MySQL > install MySQL > install MySQL > install MySQL

Then we change the initial password to root as needed:

MySQL -u root -p use MySQL; MySQL -u root -p use MySQL; update user set authentication_string=password('root') where user='root'; flush privileges;Copy the code

If you want to configure remote access, you need to configure remote access and inbound rules:

To configure remote access for user root, run the following command in MySQL:

update user set host = '%' where user = 'root';
flush privileges;
Copy the code

Configuring inbound rules requires first searching for firewalls and then selecting Windows Defender Firewall with Advanced Security:

Then click on inbound Rule and select New Rule:

After selecting the port, click Next:

Enter port 3306 and continue to select the next step. Finally, you can set a name and click Finish:

Then to test the connection, first use ipconfig to check the local IP:

Then use Navicat locally to test the connection:

Linux

On Linux, I installed mysql-5.7.34-linux-glibc2.12-x86_64, and installed the zip package (see the zip package link at the end of the article). First, I unzipped the zip package to the specified folder:

Move position after decompression:

Sudo mv mysql - 5.7.34 - Linux - glibc2.12 x86_64 / usr/local/mysqlCopy the code

Sudo vim /etc/profile command to open the profile file and add the following configuration to the end of the file:

export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
Copy the code

Run the source /etc/profile command to configure environment variables for MySQL.

To view the installation information, run the mysqld -v command:

Then run vim /etc/my. CNF to modify the default configuration file as follows:

Datadir = /usr/local/mysql/ datadir = /usr/local/mysql/dataCopy the code

Then enter the following command on the console to initialize:

mysqld --initialize
Copy the code

You can see that the console generates a password for root by default:

Then run the following command to add the corresponding permissions:

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd $MYSQL_HOME
chown -R mysql.mysql .
Copy the code

Run $MYSQL_HOME/support-files/mysql.server start to start the mysql service. Then run the following command to change the password and set the remote connection:

mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;
use mysql;
update user set host = '%' where user = 'root';
flush privileges;
Copy the code

Then run the following command to open port 3306:

systemctl start firewalld
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
Copy the code

Then look at the local IP:

Then use Navicat to test the connection:

MacOS

I installed mysql-5.7.31-MacOS10.14-x86_64, just click it as prompted, especially note that the following pop-up box will appear in the middle of the process, indicating the default root account password, please remember: Need to modify later:

After the installation is successful, you can see the following information in system preferences:

MySQL Server: Start MySQL Server:

Then enter vim ~/.bash_profile to append the following configuration to the file:

export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
Copy the code

To verify this, run source ~/.bash_profile, and then run mysqld -v:

Then run the following command to change the password and set up a remote connection:

If you forget your password, You can refer to https://blog.csdn.net/qq_36898043/article/details/79236674 mysql -u root -p ALTER USER 'root' @ 'localhost' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER; use mysql; update user set host = '%' where user = 'root'; flush privileges;Copy the code

For convenience, go to System Preferences -> Security & Privacy to ensure that the firewall is turned off:

Then use view local IP address:

Then use Navicat to test the connection:

At this point, you’re done!

Links to resources

Link: pan.baidu.com/s/1Gg9IwgvV… Extraction code: K9I2

The Windows website links: cdn.mysql.com//Downloads/…

Vcredist_x64 download address: download.microsoft.com/download/F/…

Linux website links: cdn.mysql.com//Downloads/…

MAC’s official website links: cdn.mysql.com/archives/my…