Learn how to download and install MySQL (Linux version) in ten minutes.

table of Contents

Download MySQL

Choose the MySQL version you want to download and download

Official website download address:
https://downloads.mysql.com/archives/community/

Below I take 5.7.24 as an example to download and install
Insert picture description here
Parameter description:

Product Version: Product version, that is, the version of MySQL

Operating System: operating system, Linux system can choose Linux Generic (Linux generic)

OS Version: system version, x86, 64bit is 64 bit, x86, 32bit is 32 bit

The following is the download connection of mysql5.7.24

https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

For the installation package, we can copy the link address as above, and then download it on linux, or download it on windows, and upload it to the linux server

Install MySQL

Download the installation package
//I directly use the wget command to download it on the linux server

wget  https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

//Unzip the compressed package, mysql-5.7.24.tar.gz is the compressed package I renamed, the original file name is mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

tar -zxvf mysql-5.7.24.tar.gz 

After the decompression is complete, there will be a mysql-5.7.24-linux-glibc2.12-x86_64 folder, as follows

[root@localhost data]# ll
总用量 629816
drwxr-xr-x. 9 root root       129 12月  8 17:19 mysql-5.7.24-linux-glibc2.12-x86_64
-rw-r--r--. 1 root root 644930593 10月  4 2018 mysql-5.7.24.tar.gz

//Rename the folder

mv mysql-5.7.24-linux-glibc2.12-x86_64/ mysql-5.7.24`

//Create a mysql group, and create a mysql user to join the mysql group

# groupadd mysql
# useradd -g mysql mysql
passwd mysql #设置密码

Note: groupadd means adding a group, useradd -g adds a user to a specific group, the above useradd -g mysql mysql, the first mysql represents the name of the group, the second represents the name of the user

//Change the group and user to which the mysql directory belongs

# chown -R mysql:mysql mysql-5.7.24/

Description: The first mysql represents the owner, the second mysql represents the group

//Create a directory to store mysql data

# mkdir /usr/mysql

//Modify the mysql configuration file, the default location of the mysql configuration file is /etc/my.cnf, we first delete the original configuration file, and then create a new configuration file (my.cnf)

The following is the original configuration file content

# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

Delete the original configuration file first

# rm -rf /etc/my.cnf

Create a new profile

[root@localhost etc]# vi my.cnf

The content is as follows

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306 
# 设置mysql的安装目录
basedir=/root/data/mysql-5.7.24
# 设置mysql数据库的数据的存放目录
datadir= /usr/mysql
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB 
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true

//Initialize mysql, first move to our mysql directory

# cd /root/data/mysql-5.7.24

#For configuration initialization, the initialization command of 5.7.24 uses mysqld --initialize instead of mysql_install_db

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

After executing the command, a temporary password (as follows) will be generated in the returned result, the following password is 6kDG/*QwSXcd

[Note] A temporary password is generated for root@localhost: 6kDG/*QwSXcd

//Start mysql, start mysql we use the mysqld_safe script in the bin directory, first move to the bin directory of mysql

# cd /root/data/mysql-5.7.24/bin/

Use the mysqld_safe script to start Mysql

./mysqld_safe --user=mysql &

Example:

[root@localhost bin]# ./mysqld_safe --user=mysql &
[1] 2875
[root@localhost bin]# 
[root@localhost bin]# Logging to '/usr/mysql/localhost.localdomain.err'.
2020-12-09T09:42:11.647387Z mysqld_safe Starting mysqld daemon with databases from /usr/mysql

//After startup, use the initial account (root) and the temporary password generated before to log in to mysql, and use mysql -uroot -p to enter the console

#Enter the following command and then enter the password. The temporary password I generated is 6kDG/*QwSXcd

  ./mysql -u root -p

Example:

[root@localhost bin]# ./mysql -u root -p  
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

//Successful login, we will enter the mysql command line mode, that is, mysql>, we will modify the password below

Modify password: set password=password('your password');

Note that it ends with;, which means the end of the sentence

Example:

mysql> set password=password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)

Set the host address of the root account, modify it to connect remotely

grant all privileges on *.* to 'root'@'%' identified by 'root';

Note: The first root above represents the root account, and the second root is the password of the root account, because I changed the root account password to root above

Example:

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)

After executing the mysql command, we can exit the mysql command mode. To exit the mysql mode, just enter quit;

Guess you like

Origin blog.csdn.net/qq_36551991/article/details/111084197