Install MySQL Server 5.7.21 in Linux environment

 

Reference: Generally, it is a network query, but you need to pay attention to the version downloaded on the MySQL official website. It is best to be accurate to the version when you google it, because the installation methods of different versions may be different, and these "differences" will cause some "pits" "! The version of this article is the latest version: mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz . Therefore , when you google on the Internet, look for the installation information of version 5.7.21 , and don't use any article for reference!

 

 Build a virtual machine first and then play: https://www.linuxidc.com/Linux/2017-04/143102.htm (The desktop version of the virtual machine image is best to use less pits...)

 

The installation process is similar, but the differences in the Linux environment will cause you to encounter various unexpected problems. The following is only for my installation process this time.

 

1.  Create a directory to store and upload the mysql installation tar package

 

cd / home

 

root@ubuntu:/home# mkdir security

 

chmod 777 /home/security/

 

 

 

2.  Use the WinSCP tool to upload the mysql installation tar package to the /home/security directory

 

 

3.  Decompress the tar package and rename the decompressed directory to mysql

 

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

 

mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql

 

Move to the /usr/local directory:

 

mv mysql /usr/local

 

 

 

4.  Check whether mysql has been installed in the Linux system before . If installed, you need to change the port number or stop the previous service and delete the relevant directory

 

ps -ef | grep mysql

 

 

 

5.  Create a user group mysql , create a user mysql and add it to the user group mysql , and give read and write permissions

 

groupadd mysql

 

useradd -r -g mysql mysql

 

chown -R mysql mysql/

 

chgrp -R mysql mysql/

 

 

 

6.  First check if the dependent package libaio is installed

 

rpm –qa | grep libaio1

 

If not, you need to install it by apt-get install libaio1 libaio-dev

 

Note: This step may also not have the rpm command, and perform the following steps ( it will take a long time ) :

 

 apt-get update

 

apt-get upgrade

 

apt-get install <packagename>

 

( ap-get is a software installation method under ubuntu , it is based on debain

 

 

 

yum is a software installation method under redhat and centos . It is based on Linux . It is best to find out your Linux system version first : cat /proc/version

 

 

 

7.  Create a configuration file, save and exit.

 

vim /etc/my.cnf

 

[client]

 

port = 3306

 

socket = /tmp/mysql.sock

 

 

 

[mysqld]

 

port = 3306

 

character_set_server=utf8

 

init_connect='SET NAMES utf8'

 

basedir=/usr/local/mysql

 

datadir=/usr/local/mysql/data

 

socket=/tmp/mysql.sock

 

log-error=/var/log/mysqld.log

 

pid-file=/var/run/mysqld/mysqld.pid

 

#Case insensitive

 

lower_case_table_names = 1

 

 

 

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

 

 

 

max_connections=5000

 

skip-grant-tables

 

default-time_zone = '+8:00'

 

Note: 3306 is the default port. If the mysql service has been installed before , the ports of client and mysqld need to be changed to other ports such as 3307 , otherwise the initialization will fail.

 

 

 

8.  Initialize the database (a more critical step)

 

#Manually edit the log file (used to record the initial password and startup log), don't write anything, just save and exit

 

cd / var / log /

 

 

 

vim mysqld.log

 

wq

 

 

 

chmod 777 mysqld.log

 

chown mysql:mysql mysqld.log

 

 

 

初始化命令:/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US

 

 

 

9.  View the initial password

 

cat /var/log/mysqld.log |grep 'root@localhost'

 

如:2018-03-28T12:50:49.180634Z 1 [Note] A temporary password is generated for root@localhost: xj7fWyj(NU!u

 

 

 

10. Start the mysql service

 

cd / var / run /

 

 

 

mkdir mysqld

 

 

 

chmod 777 mysqld

 

 

 

cd mysqld

 

 

 

vim mysqld.pid

 

 

 

chmod 777 mysqld.pid

 

 

 

chown mysql:mysql mysqld.pid

 

 

 

/usr/local/mysql/support-files/mysql.server start

 

 

 

/usr/local/mysql/bin/mysql -uroot –p' xj7fWyj(NU!u' (replace with the initial password in step 9 )

 

Note: There is no space between -p and the password, this is a pit! There are lots of blanks on the internet .

 

can be seen:

 

mysql: [Warning] Using a password on the command line interface can be insecure.

 

Welcome to the MySQL monitor.  Commands end with ; or \g.

 

Your MySQL connection id is 2

 

Server version: 5.7.21 MySQL Community Server (GPL)

 

 

 

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>

 

 

 

11. Modify the initial password of the root user

 

Since the above password is too complicated, modify the password defined by yourself. Note that the sql statement of version 5.7.21 is:

 

mysql> use mysql;

 

Reading table information for completion of table and column names

 

You can turn off this feature to get a quicker startup with -A

 

 

 

Database changed

 

mysql> update user set authentication_string=PASSWORD('123456') where User='root';

 

Query OK, 1 row affected, 1 warning (0.05 sec)

 

Rows matched: 1  Changed: 1  Warnings: 1

 

 

 

12. Set boot auto-start

 

cd /usr/local/mysql/support-files

 

 

 

cp mysql.server /etc/init.d/mysqld

 

 

 

chkconfig --add mysqld

 

Note: The chkconfig command may not be available here. . this way:

 

apt-get install sysv-rc-conf

 

cp /usr/sbin/sysv-rc-conf /usr/sbin/chkconfig

 

chkconfig mysqld on

 

Afterwards check:

 

chkconfig –list can discover mysql services:

 

mysqld       2:on       3:on    4:on    5:on

 

The description was successful.

 

 

 

13. Check whether the mysql service is installed successfully:

 

ps -ef | grep mysql

 

Discover:

 

root      29429      1  0 05:55 pts/17   00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/var/run/mysqld/mysqld.pid

 

mysql29707294290 05:55 pts/1700:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/tmp/mysql.sock --port=3306           

 

root      29776  13540  0 05:56 pts/17   00:00:00 /usr/local/mysql/bin/mysql -uroot -px xxxxxxxxxx

 

root      30907  28335  0 06:10 pts/19   00:00:00 grep --color=auto mysql

 

And whether port 3306 is successfully opened and occupied by MySQL :

 

lsof -i:3306

 

result:

 

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

 

mysqld  29707 mysql   19u  IPv6 293124      0t0  TCP *:mysql (LISTEN)

 

 

 

Next, you can try it with the navicat connection tool! (Currently only the root user, the process of creating other accounts is omitted)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326025576&siteId=291194637