云环境安装数据库快速完成流程

华为指导云主机mysql安装流程:

前言,最近需要在云主机在搞一台数据库做新测试,传统二进制安装太麻烦,提交了华为工单,得到了华为工程师发来的文档,然后照着完成了从安装到配置的过程,做了一个笔记供以后需要在查看。

以下操作为华为发的资料记录,比较精简快速安装数据库,比网上教程精简多了。

第一步安装数据库。以下资料来源于华为技术整理

安装MySQL

依次执行以下命令,安装MySQL

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

 

yum -y install mysql57-community-release-el7-10.noarch.rpm

 

yum -y install mysql-community-server --nogpgcheck

 

依次执行以下命令,启动MySQL服务并设置开机自启动。

systemctl start mysqld

 

systemctl enable mysqld

 

查看MySQL运行状态。

systemctl status mysqld.service

 

 

[root@ecs-adc3 ~]# systemctl status mysqld.service

● mysqld.service - MySQL Server

   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

   Active: active (running) since Mon 2021-08-16 19:33:40 CST; 36s ago

     Docs: man:mysqld(8)

           http://dev.mysql.com/doc/refman/en/using-systemd.html

 Main PID: 7916 (mysqld)

   CGroup: /system.slice/mysqld.service

           └─7916 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

 

Aug 16 19:33:35 ecs-adc3 systemd[1]: Starting MySQL Server...

Aug 16 19:33:40 ecs-adc3 systemd[1]: Started MySQL Server.

 

 

执行以下命令,获取安装MySQL时自动设置的root用户密码。

grep 'temporary password' /var/log/mysqld.log

 

回显如下类似信息。

 

2018-08-29T07:27:37.541944Z 1 [Note] A temporary password is generated for root@localhost: 2YY?3uHUA?Ys

 

执行以下命令,并按照回显提示信息进行操作,加固MySQL

mysql_secure_installation

 

 

Securing the MySQL server deployment.

 

Enter password for user root:    #输入上一步骤中获取的安装MySQL时自动设置的root用户密码

The existing password for the user account root has expired. Please set a new password.

 

New password:  #设置新的root用户密码

 

Re-enter new password:   #再次输入密码

The 'validate_password' plugin is installed on the server.

The subsequent steps will run with the existing configuration of the plugin.

Using existing password for root.

 

Estimated strength of the password: 100

Change the password for root ? ((Press y|Y for Yes, any other key for No) : N   #是否更改root用户密码,输入N

 

 ... skipping.

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

 

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y   #是否删除匿名用户,输入Y

Success.

 

Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.

 

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y   #禁止root远程登录,输入Y

Success.

 

By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.

 

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y   #是否删除test库和对它的访问权限,输入Y

 - Dropping test database...

Success.

 

 - Removing privileges on test database...

Success.

 

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

 

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y   #是否重新加载授权表,输入Y

Success.

 

All done!

 

以上为安装过程,接下来记录配置过程。

 

 

 

 

 

 

 

配置流程

在配置以下操作时需要登录数据库使用命令登陆
mysql -h localhost -u root -P 3306 -p

 

配置用户和地址权限

root 用户可以登陆所有帐户

create user 'root'@'%' identified by '3RSG1v7Sz,iv'

设置权限,任何地方都能登

grant all privileges on *.* to 'root'@'%' with grant option;

刷新权限

flush privileges

 

exit  退出登陆数据库进行全局端口配置

 

配置端口 3306,通过以下命令开启3306

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --reload  重启防火墙

查看开启的端口

firewall-cmd --list-port  

云服务器需要配置安全组,以上操作完成mysql配置数据库

 

如有不行可能需要重启计算机   

 

有时候需要操作防火墙,关于防火墙相方面,关掉防火墙,以下是附属技术,关于防火墙

1、命令行界面输入命令“systemctl status firewalld.service”并按下回车键。

 

2、然后在下方可度以查看得到“activerunning,此时说明防火墙已经被打开了。

 

3、在命令行中输入systemctl stop firewalld.service命令,进行关闭防火墙。

 

4、然后再使用命令systemctl status firewalld.service,在下方出现disavtivedead),这权样就说明防火墙已经关闭。

 

5、再在命令行中输入命令“systemctl disable firewalld.service”命令,即可永久关闭防火

 

posted @ 2023-02-21 15:29  稷下元歌  阅读(27)  评论(0编辑  收藏  举报