Linux system installation and deployment of MySQL complete tutorial (graphic and text detailed explanation)

Foreword: Recently, I read a lot of tutorials about Linux installation and deployment of MySQL on the Internet. There are always some minor problems when deploying by myself, such as: version conflicts, configuration failures and startup failures, etc. The hard work pays off, and finally the installation and deployment is successful. Yes, so this blog records how I installed and deployed MySQL step by step. Every line of code has been strictly tested. The pit bloggers have already stepped on it for everyone. The complete and detailed steps are here. This article is in the blog, hereby share it!

Blogger's other deployment tutorials:

1. Jenkins deploys front-end and back-end separation projects: The most complete graphic tutorial for Jenkins deployment front-end and back-end separation projects (hands-on teaching)

2. Docker deploys front-end and back-end separation projects: deploy front-end and back-end separation projects through Docker (pro-test available)

3. Linux system deployment Tomcat: Linux system deployment Tomcat detailed tutorial (graphic explanation)

4. Deploy Nginx in Linux system: Detailed tutorial on deploying Nginx in Linux system (graphic explanation)

5. Linux system configuration Maven: Linux system configuration Maven environment detailed tutorial (graphic explanation)

6. Linux system configuration Node.js: Linux system configuration Node.js environment detailed tutorial (graphic explanation)

7. Linux system installation and deployment of Redis: A complete tutorial on Linux system installation and deployment of Redis (detailed explanation with pictures and texts)

8. Linux system installation and deployment of MongoDB: A complete tutorial on Linux system installation and deployment of MongoDB (detailed explanation with pictures and texts)

9. Linux system installation and deployment of Jenkins: Linux system installation and deployment of Jenkins detailed tutorial (graphic explanation)

10. Pagoda panel deployment front-end separation project: Hands-on teaching using the pagoda panel deployment front-end separation project (full details)

Table of contents

1. Prepare the MySQL installation package

2. Install MySQL

3. Create user groups and users

Fourth, configure MySQL

5. Initialize MySQL

6. Start MySQL 

7. Log in and change the initial password

8. Modify access rights

9. Release port number

Ten, Navicat access MySQL

12. Set the boot to start automatically

13. Summary


1. Prepare the MySQL installation package

This is the official website: https://dev.mysql.com/downloads/mysql/5.7.html

After entering, the system selects Linux - Generic, and finally selects 64-bit and clicks Download

Choose to download directly

Note: The reason why I chose version 5.7 here is because the deployment of the latest version always had the problem of initialization failure, so I chose a more stable version. 

2. Install MySQL

Here I pre-reinstalled the system on my Huawei cloud server, just to explain the construction process step by step cleanly and completely.

1. Create a new mysql folder in the root directory (the picture is convenient)

mkdir mysql

2. Enter the directory

cd /mysql

3. Upload the downloaded compressed package to the Linux server (Xftp)

​ 

4. Unzip

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

5. After the decompression is complete, rename the decompressed directory name, it is too long

mv mysql-5.7.43-linux-glibc2.12-x86_64/ mysql-5.7

3. Create user groups and users

1. Create a user group named mysql

groupadd mysql

 2. Add user htt to mysql user group

useradd -r -g mysql htt

Fourth, configure MySQL

1. Go to the MySQL directory that you just decompressed

cd /mysql/mysql-5.7

2. Create a directory named data

mkdir data

3. Give the htt user in the user group the permission of the data directory

chown htt:mysql -R /mysql/mysql-5.7/data/

4. Configure the my.cnf file

vim /etc/my.cnf

5. Delete all the content in the my.cnf file and copy the following content

[mysqld]
bind-address=0.0.0.0
port=3306
user=htt
basedir=/mysql/mysql-5.7
datadir=/mysql/mysql-5.7/data
socket=/tmp/mysql.sock
log-error=/mysql/mysql-5.7/data/mysql.err
pid-file=/mysql/mysql-5.7/data/mysql.pid
max_connections=10000
max_user_connections=2000
wait_timeout=200
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
lower_case_table_names=1

Detailed command

parameter explain
bind-address=0.0.0.0 Set the IP address for MySQL to bind and monitor. 0.0.0.0 means to monitor all IPs and allow remote connections.
port=3306 Set the port number of the MySQL service, the default is 3306
user=htt Specify the system user running the mysqld process as htt
basedir=/mysql/mysql-5.7 Set the MySQL installation base directory
datadir=/mysql/mysql-5.7/data Set the MySQL data file directory
socket=/tmp/mysql.sock The Unix socket file path used when setting the local connection
log-error=/mysql/mysql-5.7/data/mysql.err Set error log file path
pid-file=/mysql/mysql-5.7/data/mysql.pid Set the file path to store the process PID
max_connections=10000 Set the maximum number of connections, including TCP and socket connections
max_user_connections=2000 Set the maximum number of concurrent connections for a single user
wait_timeout=200 Set the idle connection timeout, in seconds
character_set_server=utf8mb4 Set server default character set
symbolic-links=0 Disable symbolic link symbolic link support
explicit_defaults_for_timestamp Set the declaration method of the default value of the timestamp column
lower_case_table_names=1 The table name is case sensitive, set to 1 means no distinction

Note: Remember to change to your own directory

6. Press the i key to enter the edit mode and paste it in

7. Press the Esc key to exit the editing mode, enter: wq to save and exit the vim editor

5. Initialize MySQL

1. First enter the bin directory of the installation directory

cd /mysql/mysql-5.7/bin

2. Initialize the MySQL data directory

./mysqld --defaults-file=/etc/my.cnf --basedir=/mysql/mysql-5.7 --datadir=/mysql/mysql-5.7/data --user=htt --initialize

Detailed command

parameter Detailed explanation
./mysqld Start the mysqld server program
--defaults-file=/etc/my.cnf Specify the configuration file path as /etc/my.cnf
--basedir=/mysql/mysql-5.7 Specify the installation directory of MySQL
--datadir=/mysql/mysql-5.7/data Specify the data directory path
--user=htt Start as the http user
--initialize Initialize the data directory, create the necessary system tables, etc.

After execution, the console reported the following error:

./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 

Execute the following command to install it:

yum -y install libaio

3. Execute the command just now, and then execute the command to view the initial password in the log

cat /mysql/mysql-5.7/data/mysql.err

The red box is the initial password, which will be used to log in to MySQL later

NYURXh_Wx5o!

6. Start MySQL 

1. Enter the support-files directory

cd /mysql/mysql-5.7/support-files

2. Run mysql.server to start the MySQL service

sudo ./mysql.server start

Start successfully!

7. Log in and change the initial password

1. Enter the bin directory of MySQL

cd /mysql/mysql-5.7/bin

2. Login to MySQL

./mysql -u root -p

3. Paste the NYURXh_Wx5o! just now, and press Enter

That's it, you're logged in!

4. Change the initial password to root

SET PASSWORD = PASSWORD('root');

  

5. Set the password expiration policy of the root user to never expire

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

6. Refresh

FLUSH PRIVILEGES;

that's it!

8. Modify access rights

1. Access the mysql library

use mysql

2. Open the remote access authority of the root user, allowing any host to use the root user to connect to the MySQL database

update user set host = '%' where user = 'root';

3. Refresh

FLUSH PRIVILEGES;

This completes the modification! 

9. Release port number

I bought a Huawei cloud server here, and the port 3306 of MySQL needs to be released in the security group, otherwise it cannot be accessed! 

Ten, Navicat access MySQL

Enter the server ip, port number, account number and password, and the connection is successful!

In this way, the installation and deployment are successful!

12. Set the boot to start automatically

1. Create a symbolic link for the MySQL service script to the system service script directory, and the file name is mysql

ln -s /mysql/mysql-5.7/support-files/mysql.server /etc/init.d/mysql

Detailed command

parameter explain
ln -s Create a symbolic link
/mysql/mysql-5.7/support-files/mysql.server The service script that comes with the MySQL database is used to control the start and stop of the MySQL server
/etc/init.d/mysql The location where the system service script is stored

2. Create a symbolic link for the MySQL client program mysql to the system command directory /usr/bin

ln -s /mysql/mysql-5.7/bin/mysql /usr/bin/mysql

Detailed command 

parameter explain
ln -s Create a symbolic link
/usr/bin/mysql Create a mysql symbolic link in the system command directory
/mysql/mysql-5.7/bin/mysql The original path of the MySQL client program mysql

3. Restart MySQL

service mysql restart

4. Add executable permissions to the /etc/init.d/mysql file

chmod +x /etc/init.d/mysql

5. Add the mysql service as a service that starts automatically at startup

chkconfig --add mysql

6. Check the service list

chkconfig --list

Level 2-5 is displayed as on, which means that it will start automatically after booting 

And that's it! 

13. Summary

The above is the complete process of how to install and deploy MySQL using Linux. If you have any questions, welcome to discuss in the comment area! 

Guess you like

Origin blog.csdn.net/HJW_233/article/details/131849773