Install and deploy MYSQL under Centos

Keywords: MySQL yum RPM firewall

Step 1: Get the mysql yum source

Get the download address of RPM packages from mysql
https://dev.mysql.com/downloads/repo/yum/

Click Download and right-click to get the download link
https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

Of course, rpm can also be downloaded directly to the local.

[root@haloo ~]# rz // Select the file you just downloaded.
Step 2: Download and install mysql source

Download the mysql source installation package first

    [root@localhost ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

If problems arise:

- bash: wget: No command found

Install wget

yum -y install wget
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

Install mysql source

yum -y localinstall mysql57-community-release-el7-11.noarch.rpm 
Step 3: Install Mysql Online
yum -y install mysql-community-server

If you encounter the following mistakes:

There is no available package mysql-community-server

No repo source installed

The following treatment is required:

Repeat step two:

rpm -ivh mysql-community-release-el7-5.noarch.rpm

Check out:

[root@master ~]# ls -1 /etc/yum.repos.d/mysql-community*
/etc/yum.repos.d/mysql-community.repo
/etc/yum.repos.d/mysql-community-source.repo

If the above information appears, it can be installed normally.

Step 4: Check whether mysql is installed
[root@haloo ~]# mysqld --version
mysqld  Ver 5.7.23 for Linux on x86_64 (MySQL Community Server (GPL))

The installed version of mysql is 5.7.23

Step 5: Start Mysql
systemctl start mysqld

Check if the startup is successful:

[root@haloo ~]# ps aux|grep mysqld 
mysql      3415  0.4  9.2 1119500 171628 ?      Sl   16:52   0:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root       3480  0.0  0.0 112720   984 pts/0    S+   16:54   0:00 grep --color=auto mysqld

As shown above, the startup is successful, pid = 3415

You can also use mysql's own command line to view the status service mysqld status, where activity represents survival

[root@haloo ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since One 2018-08-20 16:52:28 CST; 52s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3412 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 3334 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3415 (mysqld)
    Tasks: 27
   CGroup: /system.slice/mysqld.service
           └─3415 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

8month 20 16:52:22 haloo systemd[1]: Starting MySQL Server...
8month 20 16:52:28 haloo systemd[1]: Started MySQL Server.

Of course, it can also be set to turn on and start.

[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload
Step 6: Modify the password

After the installation of mysql is completed, a temporary default password is generated for root in the / var/log/mysqld.log file.

[root@haloo ~]# vim /var/log/mysqld.log 
2018-08-20T08:52:24.328424Z 1 [Note] A temporary password is generated for root@localhost: D&!Uth(Hq4sg

The default password given here is D&Uth (Hq4sg, is it difficult to operate, so we need to set a password that we are used to and remember well?)

Change Password:

[root@haloo ~]# mysql -u root -p
Enter password: 

Here you need to enter the password for the default installation of Mysql. That's D &! Uth (Hq4sg).

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxx';
Query OK, 0 rows affected (0.00 sec)

Note the password format you enter (the default password policy requires that the password must be a combination of special letters of upper and lower case letters, at least 8 bits)

Step 7: Setting Allow Remote Logon

mysql is not allowed to log on remotely by default. We need to set it up and the firewall opens port 3306.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxxx' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> exit;
Bye

Xxxxx stands for the password you entered last time

Open Firewall Port 3306

[root@haloo ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@haloo ~]# firewall-cmd --reload
success

Note that if the port number you set is not 3306, then your port here needs to be changed to the port number you set.
Now we can manage our MYSQL database through remote connection.

Posted by ozzythaman on Wed, 15 May 2019 00:37:38 -0700