MySql Foundation - Building MySql Database: Installing MySql-server, MySql-client

Posted by beaux1 on Sat, 02 May 2020 18:45:31 +0200

1 Build MySQL Server
1.1 Question

This case requires familiarity with the use of MySQL's official installation package to quickly build a database server:

Install MySQL-server, MySQl-client packages
Modify the password of the database user root
Confirm MySQL service program is running and root is controllable

1.2 Program

This course will use the 64-bit RHEL 7 operating system. The version of the MySQL database is 5.7.17.

Visit http://dev.mysql.com/downloads/mysql/, find the MySQL Community Server download page, choose Red Hat Enterprise Linux 7/Oracle Linux, and then select the 64-bit bundle package to download

Note: When downloading MySQL software, you need to log in with an Oracle website account. If you don't, please register one first (free) according to the page prompt.
Step 1.3

The following steps are required to implement this case.

Step 1: Preparations

1) Stop mariadb Service

[root@localhost ~]# systemctl stop mariadb

2) Delete/etc/my.cnf profile

This configuration file is provided by the mariadb-libs library that comes with RHEL:

[root@localhost ~]# rm -rf /etc/my.cnf

3) Delete data

[root@localhost ~]# rm -rf /var/lib/mysql/*

4) Uninstall the package (no uninstalled packages will be shown)

[root@localhost ~]# rpm -e --nodeps mariadb-server mariadb `
Warning: /var/log/mariadb/mariadb.log has been saved as/var/log/mariadb/mariadb.log.rpmsave

Step 2: Install the package

1) Some dependent packages may be missing when installing mysql and need to be installed separately in advance

[root@localhost ~]# yum -y install perl-Data-Dumper perl-JSON perl-Time-HiRes

2) Physical machine transfers decompressed packages to virtual machine 192.168.4.1

[root@room9pc01 ~]# cd desktop            
[root@room9pc01 desktop]# scp mysql-5.7.17.tar 192.168.4.1:/root/ //package to virtual machine
root@192.168.4.1's password:
mysql-5.7.17.tar     100%  543MB  95.6MB/s   00:05

3) Virtual machine 192.168.4.1 decompresses mysql-5.7.17.tar package

[root@localhost ~]# Tar-xvf mysql-5.7.17.tar //unzip MySQL package
./mysql-community-client-5.7.17-1.el7.x86_64.rpm
./mysql-community-common-5.7.17-1.el7.x86_64.rpm
./mysql-community-devel-5.7.17-1.el7.x86_64.rpm
./mysql-community-embedded-5.7.17-1.el7.x86_64.rpm
./mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm
./mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm
./mysql-community-libs-5.7.17-1.el7.x86_64.rpm
./mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm
./mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm
./mysql-community-server-5.7.17-1.el7.x86_64.rpm
./mysql-community-test-5.7.17-1.el7.x86_64.rpm

4) Installation

[root@localhost ~]# yum -y install perl-JSON
[root@localhost ~]# rm -rf mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm
[root@localhost ~]# rpm -Uvh mysql-community-*.rpm
[root@localhost ~]# rpm -qa |grep -i mysql

Step 3: Start the MySQL database service and set the startup self-startup

[root@localhost ~]# systemctl start mysqld //start mysql service
[root@localhost ~]# systemctl enable mysqld //Set Start-Up Self
[root@localhost ~]# systemctl status mysqld //View mysql service status
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 2 2018-08-28 10:03:24 CST; 8min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 4284 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─4284 /usr/sbin/mysqld --daemonize --pid-file=/var/r...
8 28/10:02:56 localhost.localdomain systemd[1]: Starting MySQ...
8 28/10:03:24 localhost.localdomain systemd[1]: Started MySQL...
Hint: Some lines were ellipsized, use -l to show in full.

Step 4: Connect to MySQL server and change password

View randomly generated root administrative passwords

[root@localhost ~]#grep 'temporary password' /var/log/mysqld.log
2017-04-01T18:10:42.948679Z 1 [Note] A temporary password is generated for root@localhost: mtoa>Av<p6Yk        //The randomly generated administrative password is mtoa>Av<p6Yk

2) Use the client command Mysql to connect to the MySQL server

When prompted for validation, fill in the random password obtained in the previous step and enter the "mysql>" environment after successful validation:

[root@localhost ~]# mysql -u root -p'mtoa>Av<p6Yk'
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 11
Server version: 5.7.17
Copyright (c) 2000, 2016, 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>                                     //Enter the SQL operating environment after successful login

//After you log in to the server with this password, you must change the password immediately or the following error will be reported:

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

3) Execute SET PASSWORD command to change password

This is actually related to the value of validate_password_policy, which defaults to 1, so the password you just set must match the length and must contain numbers, lowercase or capital letters, and special characters.If we don't want password settings to be that complex, we need to modify two global parameters: validate_password_policy and validate_password_length.The default value of validate_password_length is 8 and the minimum value is 4. If you explicitly specify that the value of validate_password_length is less than 4, the value of validate_password_length will be set to 4, although no error will be reported.

You can refer to the following instructions:

mysql>set global validate_password_policy=0;      //Verify Length Only
Query OK, 0 rows affected (0.00 sec)
mysql>set global validate_password_length=6;     //Change password length, default is 8 characters 
Query OK, 0 rows affected (0.00 sec)
mysql> alter user user() identified by "123456";  //Modify login password
Query OK, 0 rows affected (0.00 sec)

The result of this is to change the password of the database user root when it is accessed from the local machine to 123 456.

Exit the "mysql>" environment, re-login for authentication, you must use a new password to log in:

mysql> exit                                  //Exit mysql>environment
Bye
[root@localhost ~]# Mysql-u root-p //login again
Enter password:                              //Enter the new password
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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.

Topics: Linux MySQL RPM MariaDB Oracle