background

In the process of project development, some Linux servers provided by Party A have strict security requirements and may not provide the root user for us to use. In this case, it is not feasible to install mysql directly after installing YUM or source code and then starting mysql. In this case, mysql needs to be installed under a non-root user. The next step is the binary installation.


Download the binary mysql installation file

Uninstall the installation package and go to the mysql official websiteDev.mysql.com/downloads/m…Select the package version and click the link on the right Looking for Previous GA Versions, Linux-Generic, x86-64 version


2. Start the installation

1. Decompress the file

The following uses the /home/liu account as an example

## Decompress tar -xvf mysql5.734.-linux-glibc212.-x86_64.tar.gz -C /home/liu
cd /home/liu
mv mysql5.734.-linux-glibc212.-x86_64 mysql5.734.Mkdir /home/liu/mysql5.734./data
mkdir /home/liu/mysql5.734./conf
Copy the code

2. Prepare the configuration file

cat > /home/liu/mysql5.734./conf/my.cnf << EOF
[client] 
default-character-set=utf8mb4

[mysql]
port = 3306
socket = /home/liu/mysql5.734./data/mysql.sock
default-character-set=utf8mb4
 
[mysqld]
port = 3306
default_storage_engine=InnoDB
basedir = /home/liu/mysql5.734.
datadir = /home/liu/mysql5.734./data
socket  = /home/liu/mysql5.734./data/mysql.sock
character-set-client-handshake = FALSE
character-set-server=utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
max_connections = 2000
max_allowed_packet = 128M
innodb_file_per_table = 1
tmp_table_size = 134217728
max_heap_table_size = 134217728

lower_case_table_names=1

log-bin = mysql-bin
max_binlog_size = 1024M
expire_logs_days = 1
log_slave_updates = 1
server-id = 1sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBST ITUTION EOFCopy the code

3. Modify environment variables

## Configure the environment variable cat >> /home/liu/.bashrc << EOFexport PATH=/home/liu/mysql5.734./bin:\$PATH EOF ## effect source. bashrc ## link sock file to/TMP, default mysql read ln -s /home/liu/mysql5.734./data/mysql.sock /tmp/mysql.sock

Copy the code

4. Initialize the database

Mysqld — defaults – file = / home/liu/mysql – 5.7.34 / conf/my CNF – user = liu – initialize

Mysqld --defaults-file=/home/liu/mysql5.734.[liu@localhost ~]$mysqld --defaults-file=/home/liu/mysql5.734./conf/my.cnf --user=liu --initialize    
2021- 04- 30T05:54:25.918199Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 10000)
2021- 04- 30T05:54:25.918287Z 0 [Warning] Changed limits: max_connections: 214 (requested 2000)
2021- 04- 30T05:54:25.918291Z 0 [Warning] Changed limits: table_open_cache: 400 (requested 2000)
2021- 04- 30T05:54:25.918421Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021- 04- 30T05:54:26.083506Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021- 04- 30T05:54:26.110619Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021- 04- 30T05:54:26.180108Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 85420f95-a978- 11eb-b8f9-080027473f54.
2021- 04- 30T05:54:26.182418Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021- 04- 30T05:54:26.682357Z 0 [Warning] CA certificate ca.pem is self signed.
2021- 04- 30T05:54:26.782180Z 1 [Note] A temporary password is generated for root@localhost: 7a8a-VU>owtq
Copy the code

5. Start the database

/ home/liu/mysql – 5.7.34 / bin/mysqld_safe – defaults – file = / home/liu/mysql – 5.7.34 / conf/my CNF – user = liu &

/home/liu/mysql5.734./bin/mysqld_safe --defaults-file=/home/liu/mysql5.734./conf/my.cnf --user=liu & ## start log: [liu@localhost ~]$2021- 04- 30T05:58:21.373237Z mysqld_safe Logging to '/ home/liu/mysql - 5.7.34 / data/localhost localdomain.. err'.
2021- 04- 30T05:58:21.399471Z mysqld_safe Starting mysqld daemon with databases from /home/liu/mysql5.734./ data # # to check the ps - ef | grep mysqld, can see the mysql normal boot [liu @ localhost ~] $ps - ef | grep mysqld liu13020 12906  0 13:58 pts/0    00:00:00 /bin/sh /home/liu/mysql5.734./bin/mysqld_safe --defaults-file=/home/liu/mysql5.734./conf/my.cnf --user=liu
liu      13381 13020  0 13:58 pts/0    00:00:00 /home/liu/mysql5.734./bin/mysqld --defaults-file=/home/liu/mysql5.734./conf/my.cnf --basedir=/home/liu/mysql5.734. --datadir=/home/liu/mysql5.734./data --plugin-dir=/home/liu/mysql5.734./lib/plugin --log-error=localhost.localdomain.err --pid-file=localhost.localdomain.pid --socket=/home/liu/mysql5.734./data/mysql.sock --port=3306
liu      13413 12906  0 14:00 pts/0    00:00:00 grep --color=auto mysqld

Copy the code

6. Login test

mysql -uroot -hlocalhost -p

##
mysql -uroot -hlocalhost -pRun the preceding command and enter the root password7[liu@localhost ~]$mysql -uroot -hlocalhost -p Enter password: Welcome to the MySQL monitor. Commands end with ;or \g.
Your MySQL connection id is 4
Server version: 5.734.-log

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 

Copy the code

So far, mysql has been successfully installed through binary.


other

1. Change the root password

This is executed by alert User

### change the password of user root.alter user user(a) identified by "123456";
flush privileges;

##日志如下:
mysql> alter user user(a) identified by "123456";
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 
Copy the code

2. If you forget the root password

If you forget the root password, restart mysql with –skip-grant-tables and change the password

/home/liu/mysql5.734./bin/mysqld_safe --defaults-file=/home/liu/mysql5.734./conf/my.cnf --skip-grant-tables & ## update mysql.user -- uroot -hlocalhost ##set authentication_string=password("123456") where user='root' and host='localhost'; flush privileges; Finally, stop the data and start the database as normal to make the password verification take effectCopy the code

3. Stop the database

This can be done by killing the process directly, but it is not recommended because it is prone to unforeseen errors that can cause problems in a production environment.

You can use mysqladmin-shutdown

/home/liu/mysql5.734./bin/mysqladmin -u root -p shutdown ## The log is as follows: [liu@localhost ~]$/home/liu/mysql5.734./bin/mysqladmin -u root -p shutdown
Enter password: 
2021- 04- 30T06:13:06.147682Z mysqld_safe mysqld from pid file /home/liu/mysql5.734./data/localhost.localdomain.pid ended
[1]+  Done                    /home/liu/mysql5.734./bin/mysqld_safe --defaults-file=/home/liu/mysql5.734./conf/my.cnf --user=liu
[liu@localhost ~]$ 
Copy the code