Centos7 快速安装 MariaDB5.5

来源:互联网 发布:h3c端口聚合interface 编辑:程序博客网 时间:2024/06/05 04:24

从最新版本的Centos系统开始,默认的是 MariaDB而不是MySQL

使用系统自带的repos安装很简单:

安装

yum install mariadb mariadb-server

启动mariadb

systemctl start mariadb

开机启动

systemctl enable mariadb

设置root密码

mysql_secure_installation

这里按照提示一步一步操作即可

mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the currentpassword for the root user.  If you've just installed MariaDB, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none):# 回车OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [Y/n] YNew password: #输入密码Re-enter new password: # 重复密码 Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] Y ... Success!Normally, root should only be allowed to connect from 'localhost'.  Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] n # 正常情况应该输入Y,我这里在自己测试服务器上直接允许远程登陆即可,注意生产环境一定要Y! ... skipping.By default, MariaDB comes with a database named 'test' that anyone canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] n # 这里不删测试服务器 ... skipping.Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] Y # 这里必须Y确认才能使修改生效 ... Success!Cleaning up...All done!  If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!

测试登录

mysql -u root -p

得到如下响应,表示成功

[root@hadoop ~]# mysql -u root -pEnter password: Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 13Server version: 10.2.11-MariaDB MariaDB ServerCopyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows in set (0.00 sec)

然后后面的操作基本跟mysql一样一样的了。

注意:

虽然前面我们设置过允许root用户远程登陆,但是

MariaDB [(none)]> exitBye[root@hadoop ~]# mysql -h 10.50.200.169 -u root -pEnter password: ERROR 1130 (HY000): Host 'hadoop1' is not allowed to connect to this MariaDB server[root@hadoop ~]#

还是不能远程登陆的。接着往下看!

关闭防火墙

systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启动

设置远程登陆

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

测试

mysql -h 10.50.200.169 -u root -p

这样就可以远程登陆了

[root@hadoop ~]# mysql -h 10.50.200.169 -u root -pEnter password: Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 16Server version: 10.2.11-MariaDB MariaDB ServerCopyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> exitBye

注意:

上面操作要成功,必须保证防火墙关闭或者添加端口3306例外;

前面环境中我直接把防火墙关了,但是目前大网络环境下,人们越来越重视安全问题,直接关防火墙是极为不推荐的!

[root@hadoop ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanentsuccess[root@hadoop ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanentsuccess[root@hadoop ~]# firewall-cmd --reloadsuccess

把端口3306添加到防火墙例外,然后必须reload一下;过一会可以从其他客户端连接一下,这样就OK了!

在提醒一下,生产环境不要暴露root用户,禁止使用root远程登陆,禁止关闭防火墙!!!

原创粉丝点击