Linux system CentOS 6.9 x64 configures jdk and MySQL 8.0 environment and grants MySQL remote access

Keywords: Linux MySQL RPM JDK Java

Blogger server version and installed jdk and mysql versions:

  • System: CentOS 6.9
  • jdk: jdk1.8_221
  • MySQL: mysql8.0.20

Relevant files needed in the configuration process (click to download from Baidu cloud):

Configure jdk

Create a new jdk folder in the environment directory

cd /home/evn
mkdir jdk

Use xftp or other file transfer tools to transfer the jdk compressed files to the jdk folder, and extract

tar -zxvf jdk-8u221-linux-x64.tar.gz

Open the profile file in etc directory, and add the following at the end of the file

vi /etc/profile
export JAVA_HOME=/home/evn/jdk/jdk1.8.0_221 ## The directory here should be replaced by the jdk directory you unzipped
export JRE_HOME=${JAVA_HOME}/jre
export PATH=$PATH:${JAVA_HOME}/bin
export CLASSPATH=./:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib

Make profile file effective immediately

source /etc/profile

verification

java -version

If the following content is displayed, the jdk configuration is successful

[root@VM_0_7_centos jdk]# java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
If the validation is not successful, check the configuration of the path in the profile file

Configure MySQL

Let's see if MySQL is already installed

Method 1:

rpm -qa|grep mysql

If there is a display, enter the following command to delete

rpm -e --nodeps filename

After deletion, enter the following command to check whether the deletion is clean

rpm -qa|grep mysql

Method 2:

View installed MySQL

yum list installed|grep mysql

If there is content, enter the following command to delete

yum remove filename

Check again after deleting

yum list installed|grep mysql

Install MySQL

Create a new mysql folder in the environment directory

cd /home/evn
mkdir mysql

Use xftp or other file transfer tools to transfer MySQL bundle installation package to MySQL directory, and extract

tar -xvf mysql-8.0.20-1.el6.x86_64.rpm-bundle.tar

Install in the following order

rpm -ivh mysql-community-common-8.0.20-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.20-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.20-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-8.0.20-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-8.0.20-1.el6.x86_64.rpm
If there is no dependency during the installation, use the yum install command to add

Initialize MySQL after installation

mysqld --initialize --user=mysql
In this step, a random password will be generated, which is required for later login to MySQL

View random password in log

cat /var/log/mysqld.log
[Server] A temporary password is generated for root@localhost: *******

Start MySQL service

service mysqld start
When the blogger starts for the first time, it fails to start without error. This problem is due to the permission allocation problem.
Solution to permission problem: chmod 777 /var/run/mysqld

Change root password

Log in mysql with the randomly generated password found in the log

mysql -u root -p 

Enter random password after entering (copy: Ctrl+insert paste: Shift+insert)

If you forget the random password, you can log in to mysql using the password free login method 

Password free login mysql change root password

Change root password

ALTER user 'root'@'%' IDENTIFIED BY 'New password';

Grant MySQL remote access

After logging in to MySQL, switch to MySQL database

 use mysql

Change domain properties to allow external access

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

Refresh permission table

FLUSH PRIVILEGES;

Execute authorization statement

grant all privileges on *.* to 'root'@'%' with grant option;
Users who use Navicat 12 or later need to change the encryption method. Users who use Navicat 12 or later can skip the following.

Modify encryption method

Reason: MySQL 8.0 introduces new feature caching_sha2_password; this password encryption method is not supported by Navicat 12 clients;
The following clients of Navicat 12 support mysql_native_password is an encryption method;

Method 1:

Enter the following statement to view the encryption method

select host,user,plugin from user;

Modify root encryption mode

update user set plugin='mysql_native_password' where user='root';

Method 2:

modify my.cnf Configuration in file

vi /etc/my.cnf

Insert the following at the end of the file

default_authentication_plugin=mysql_native_password

Exit after saving the changes (press Esc first, enter: wq and enter)

Restart MySQL service

service mysqld restart
At this point, all configurations are finished. If you think this article is helpful to you, please click "like" to support it. The blogger will be very happy

Posted by daydreamer on Tue, 26 May 2020 23:56:40 -0700