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 Server
the server , you only need to Windows
use mstsc
the command to enter, but Linux
the 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.
After entering the software, right-click the blank area on the left and create a new connection , as shown in the figure below.
After the creation is completed, select SSH
the connection method, enter the IP address and user name in turn , and then click OK
the button , as shown in the figure below.
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.
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
Linux
After entering , first create MySQL
the installation folder of , please enter the following commands in sequence.
Enter the user directory.
cd /usr/local
Create MySQL
a folder .
mkdir mysql
Go into the created MySQL
folder .
cd mysql
Download and unzip MySQL
the 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 MySQL
data storage folder data
.
cd mysql8
mkdir data
So far, **mysql**
the installation directory structure is shown in the figure below, please compare and check.
2.2 MySQL user authorization
MySQL
After 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 profile
the file , the command is as follows.
vim /etc/profile
Tip: After entering the profile file, press
i
the key , which means to start typing, as shown in the figure below.
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
ESC
the key , and then enter in sequence:wq
, as shown in the figure below, which means to save and exit (exit).
2.4 Initialize MySQL
After the environment configuration is completed, it enters the initialization MySQL
phase .
First MySQL
enter bin
the 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.
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.
MySQL
In the directory of , there is a support-files
folder.
MySQL
Services are stored in it , as shown in the figure below.
Students need to copy the directory to etc
the 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/
MySQL
Edit etc
the 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
MySQL
The command to start is as follows.
service mysqld start
After successful startup, as shown in the figure below.
If the startup fails, first check whether port 3306 is occupied.
2.7 Cancel permission verification and delete the initial password
MySQL
After 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.
/etc
Open my.cnf
the configuration file under the directory, add it [mysqld]
below skip-grant-tables
, the command is as follows.
cd /etc
vim my.cnf
Then restart MySQL
the service , the directory is as follows.
/etc/init.d/mysqld restart
Then enter the offline version MySQL
.
cd /usr/local/mysql/mysql8/bin
./mysql
MySQL
After 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 root
the 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
After saving, start the MySQL service again.
/etc/init.d/mysqld restart
Enter MySQL, the command is as follows.
mysql -u root -p
First query the currently existing users, the command is as follows.
select user,host from user;
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.