How to download and install MySQL8 on Linux, and open external network access

Author homepage : Designer Xiaozheng
Author brief introduction : A Java full-stack software engineer from Ningbo, Zhejiang, responsible for the development and management of the company's OA projects, focusing on front-end and back-end software development (Vue, SpringBoot and WeChat applets), system customization, and remote technical guidance. Certified lecturer of CSDN Academy and Blue Bridge Cloud Class, high-quality creator in the full-stack field. Love technology, focus on business, open cooperation, willing to share, look forward to growing up with you and me!
Main direction : Vue, SpringBoot, WeChat applet

Received a request from a customer today:

I need to deploy my system to Linux!

So I started exploring today and wrote a blog to record it.

1. Login to Linux

To connect to Window Serverthe server , you only need to Windowsuse mstscthe command to enter, but Linuxthe system cannot, you need to download the third-party connection software.

I use MobaXterm, MobaXterm download address .

After downloading, install it normally, and run it after the installation is complete, as shown in the figure below.

insert image description here

After entering the software, right-click the blank area on the left and create a new connection , as shown in the figure below.

insert image description here


After the creation is completed, select SSHthe connection method, enter the IP address and user name in turn , and then click OKthe button , as shown in the figure below.

insert image description here

After the connection is successful, as shown in the figure below.

Tip: If you log in for the first time, you need to enter the server password when entering. Students copy and paste, press enter.

insert image description here


2. Download and install MySQL

MySQL is a relational database management system, developed by the Swedish company MySQL AB, which is a product of Oracle, download the official website address .

2.1 MySQL download and install

LinuxAfter entering , first create MySQLthe installation folder of , please enter the following commands in sequence.
Enter the user directory.

cd /usr/local

Create MySQLa folder .

mkdir mysql

Go into the created MySQLfolder .

cd mysql

Download and unzip MySQLthe installation package.

wget wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.30-el7-x86_64.tar.gz
tar zxvf mysql-8.0.30-el7-x86_64.tar.gz

Rename the folder to mysql8.

mv mysql-8.0.30-el7-x86_64 ./mysql8

Create a MySQLdata storage folder data.

cd mysql8
mkdir data

So far, **mysql**the installation directory structure is shown in the figure below, please compare and check.

insert image description here


2.2 MySQL user authorization

MySQLAfter installation, you need to register the initial user and complete the administrator authorization .

First create a new user, the command is as follows.

groupadd mysql
useradd -g mysql mysql

Tip: The two mysqls are user groups and user names respectively, and students configure them according to their own needs.

Then authorize the new user just created, and give the data folder read and write permissions , the command is as follows.

chown -R mysql:mysql /usr/local/mysql/mysql8
chmod 750 /usr/local/mysql/mysql8/data -R

2.3 Configure the MySQL environment

First edit profilethe file , the command is as follows.

vim /etc/profile

Tip: After entering the profile file, press ithe key , which means to start typing, as shown in the figure below.

insert image description here

Add the following command to the last line of the file .

export PATH=$PATH:/usr/local/mysql/mysql8/bin:/usr/local/mysql/mysql8/lib

Tip: After the addition is complete, press ESCthe key , and then enter in sequence :wq, as shown in the figure below, which means to save and exit (exit).

insert image description here


2.4 Initialize MySQL

After the environment configuration is completed, it enters the initialization MySQLphase .

First MySQLenter binthe directory of , the directory is as follows.

cd bin
./mysqld --user=root --basedir=/usr/local/mysql/mysql8 --datadir=/usr/local/mysql/mysql8/data/ --initialize

After the initialization is complete, the system will give the initial password 6Ju+BGsta/dJ, as shown in the figure below.

insert image description here

Tip: The data folder needs to be cleared before initialization, the command is rm -rf data.

2.5 MySQL Directory Authorization

In the operating system, the most important thing is the operation permission. If there is no permission, many things cannot be done.

MySQLIn the directory of , there is a support-filesfolder.

insert image description here
MySQLServices are stored in it , as shown in the figure below.

insert image description here
Students need to copy the directory to etcthe directory and grant permission , the command is as follows.

cp -a ./support-files/mysql.server /etc/init.d/mysql 
cp -a ./support-files/mysql.server /etc/init.d/mysqld

chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysql
chmod +x /etc/init.d/mysqld

mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql/ 
chown -R mysql:mysql /tmp/

MySQLEdit etcthe configuration file for .

sudo vim my.cnf

The configuration content is as follows.

[client]  
default-character-set=utf8  
#password   = your_password  
port= 3306 
socket= /tmp/mysql.sock  
 
[mysqld]  
basedir=/usr/local/mysql/mysql8
datadir=/usr/local/mysql/mysql8/data
default-storage-engine=INNODB  
character-set-server=utf8  
collation-server=utf8_general_ci  
port= 3306 
socket= /tmp/mysql.sock  
skip-external-locking  
key_buffer_size = 16K  
max_allowed_packet = 1M  
table_open_cache = 4 
sort_buffer_size = 64K  
read_buffer_size = 256K  
read_rnd_buffer_size = 256K  
net_buffer_length = 2K  
thread_stack = 128K  
server-id   = 1 

[mysqldump]  
quick  
max_allowed_packet = 16M  

[mysql]  
no-auto-rehash  

[myisamchk]  
key_buffer_size = 8M  
sort_buffer_size = 8M  

[mysqlhotcopy]  
interactive-timeout 

2.6 Start MySQL

MySQLThe command to start is as follows.

service mysqld start

After successful startup, as shown in the figure below.

insert image description here

If the startup fails, first check whether port 3306 is occupied.

2.7 Cancel permission verification and delete the initial password

MySQLAfter the startup is successful, the next step is to modify the default password.

Students can skip steps 2.7 and 2.8 if they can log in with the initial password.

/etcOpen my.cnfthe configuration file under the directory, add it [mysqld]below skip-grant-tables, the command is as follows.

cd /etc
vim my.cnf

insert image description here

Then restart MySQLthe service , the directory is as follows.

/etc/init.d/mysqld restart

Then enter the offline version MySQL.

cd /usr/local/mysql/mysql8/bin
./mysql

MySQLAfter entering , first switch the database to mysql.

USE mysql ;
update user set authentication_string = '',Host = '%' where user = 'root';
flush privileges;
exit;

Note that the password field for MySQL 8.0 is authentication_string, not password!


2.8 Restore authority verification, set password

In step 2.7, the password of rootthe account blanked, and then you can log in with a blank password .

Enter the configuration file directory, open the configuration file, restore permission verification, the command is as follows.

cd /etc
vim my.cnf

insert image description here
After saving, start the MySQL service again.

/etc/init.d/mysqld restart

insert image description here

Enter MySQL, the command is as follows.

mysql -u root -p

insert image description here

First query the currently existing users, the command is as follows.

select user,host from user;

insert image description here

Then change the password, the command format is as follows.

alter user '用户名'@'hostname' identified by 'newpwd';

To change the password to 123456, the command is as follows.

alter user '用户名'@'%' identified by '123456';

At this point, the database has been initialized.

insert image description here

Guess you like

Origin blog.csdn.net/qq_41464123/article/details/128850002