Alibaba cloud CentOS 7.6 installation of mysql8

Create mysql users and user groups

groupadd mysql
useradd -g mysql mysql
passwd mysql

Uninstalling mariadb from the system

#query 
rpm -qa|grep mariadb

Return mariadb-libs-5.5.60-1.el7_.x86_

#uninstall
rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64

Return

error: Failed dependencies:
        libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
        libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
#Forced unloading
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

Download mysql rpm

Download mysql rpm
Choice
Red Hat Enterprise Linux / Oracle Linux
Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
RPM Bundle
Get download address
https://cdn.mysql.com//Downlo...

wget "https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar"

tar -xvf mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar

install

Installation dependency

yum install -y libaio.x86_64 libaio-devel.x86_64 
yum install -y openssl-devel.x86_64 openssl.x86_64 
yum install -y perl.x86_64 perl-devel.x86_64 
yum install -y perl-JSON.noarch 
yum install -y autoconf

Necessary installation, pay attention to the order and dependency

rpm -ivh mysql-community-common-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.13-1.el7.x86_64.rpm

Unnecessary installation, attention to order, dependency

rpm -ivh mysql-community-libs-compat-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.0.13-1.el7.x86_64.rpm

Initialize database

mysqld --initialize --console

Modify directory permissions

This step must be after initializing the database!!!
After installation, the default permissions are mysql users and user groups. If not, change

chown -R mysql:mysql /var/lib/mysql/

Start with root

systemctl start mysqld

If startup fails, view the log

tail -n 100 /var/log/mysqld.log 

View password at initialization

After successful startup, you can view the randomly generated initialization password

cat /var/log/mysqld.log | grep password

Log in to MYSQL to modify the MySQL user password

mysql -u root -p

#Change Password
alter user 'root'@'localhost' identified by  'yourpassword';

#Remote setup
use mysql;
update user set host='%' where user='root';

#Authorize the user name and give any host access to data
grant all privileges ON *.* to 'root'@'%' with grant option;
flush privileges;

Add mysql user, create database, authorize

create user 'flame'@'%' identified by 'password';
create database flame;
grant all privileges on flame.* to 'flame'@'%';
flush privileges;

centos7 firewall open port

# Open 3306 port
firewall-cmd --zone=public --add-port=3306/tcp --permanent
#heavy load
firewall-cmd --reload
#View state
firewall-cmd --list-all

Alicloud port security group settings

Security group description
Add a new input direction rule for 3306 port

production environment

mysql_secure_installation

Can do the following

  • Set password for root
  • Delete anonymous account
  • Cancel root remote login
  • Delete test library and access to test library
  • Refresh authorization table for changes to take effect

Related management orders

#mysql start
systemctl start mysqld.service
#End
systemctl stop mysqld.service
#restart
systemctl restart mysqld.service
#Boot from boot
systemctl enable mysqld.service

Keywords: MySQL RPM MariaDB yum

Added by steve55 on Sun, 01 Dec 2019 03:37:24 +0200